Changeset 12046 for issm/trunk-jpl/src
- Timestamp:
- 04/18/12 09:10:45 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/matlab/io/WriteMatlabData.cpp
r12043 r12046 28 28 for(int i=0;i<M;i++){ 29 29 for(int j=0;j<N;j++){ 30 tmatrix[ i*N+j]=matrix[j*M+i];30 tmatrix[j*M+i]=matrix[i*N+j]; 31 31 } 32 32 } … … 49 49 50 50 if(matrix){ 51 52 51 /*convert to double matrix using Matlab's memory manager*/ 53 52 double* tmatrix=(double*)mxMalloc(M*N*sizeof(double)); 54 53 for(int i=0;i<M;i++){ 55 54 for(int j=0;j<N;j++){ 56 tmatrix[ i*N+j]=(double)matrix[j*M+i];55 tmatrix[j*M+i]=(double)matrix[i*N+j]; 57 56 } 58 57 } … … 61 60 mxSetN(dataref,(mwSize)N); 62 61 mxSetPr(dataref,(double*)tmatrix); 63 64 62 } 65 63 else{ … … 238 236 /*Now transpose the matrix and allocate with Matlab's memory manager: */ 239 237 tmatrix_ptr=(double*)mxMalloc(rows*cols*sizeof(double)); 240 for(i=0;i< cols;i++){241 for(j=0;j< rows;j++){242 tmatrix_ptr[ i*rows+j]=matrix_ptr[j*cols+i];238 for(i=0;i<rows;i++){ 239 for(j=0;j<cols;j++){ 240 tmatrix_ptr[j*rows+i]=matrix_ptr[i*cols+j]; 243 241 } 244 242 } … … 299 297 /*Toolkit*/ 300 298 /*FUNCTION SetStructureField{{{1*/ 301 void SetStructureField(mxArray* dataref,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer){ 302 303 /*Intermediary*/ 304 int i1,i2; 305 mxArray *pfield = NULL; 306 307 /*Copy field using Matlab's API and transpose*/ 308 double* fieldcopy=NULL; 309 if (fieldrows*fieldcols){ 310 fieldcopy=(double*)mxMalloc(fieldrows*fieldcols*sizeof(double)); 311 for(i1=0;i1<fieldrows;i1++){ 312 for(i2=0;i2<fieldcols;i2++){ 313 fieldcopy[fieldcols*i1+i2]=fieldpointer[fieldrows*i2+i1]; 314 } 315 } 316 } 317 318 /*Set matlab field*/ 319 pfield=mxCreateDoubleMatrix(0,0,mxREAL); 320 mxSetM(pfield,fieldcols); 321 mxSetN(pfield,fieldrows); 322 mxSetPr(pfield,fieldcopy); 323 mxSetField(dataref,0,fieldname,pfield); 324 } 325 /*}}}*/ 299 void SetStructureField(mxArray* dataref,const char* fieldname,int M,int N,double* fieldpointer){ 300 301 mxArray* field = NULL; 302 303 304 /*Convert field*/ 305 WriteData(&field,fieldpointer,M,N); 306 307 /*Assign to structure*/ 308 mxSetField(dataref,0,fieldname,field); 309 } 310 /*}}}*/
Note:
See TracChangeset
for help on using the changeset viewer.