Problem using mxGetPr for accessing array of type double

조회 수: 3 (최근 30일)
AP
AP 2012년 10월 21일
Dear All,
I am using mxGetPr function to retrieve the data of an array of type double.
#include "matrix.h"
#include "math.h"
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
#define FACES prhs[0]
int nFaces;
double *faces;
nFaces = mxGetM( FACES );
faces = mxGetPr( FACES );
for( int i=0; i<nFaces ; i++ )
mexPrintf("(%d): [ %d ]\n", i, faces[i] );
}
When I print the value of the first column of prhs[0], it's all zero while those of the input array is not zero and has different values. I checked with the documentation and many examples onlines and didn't see any difference between my code and theirs.
Could someone help me how to access the value of the elements of prhs[0] correctly? I also checked the type of input array using whos command and it is double.
Thanks,
Ahmad
  댓글 수: 1
AP
AP 2012년 10월 21일
I changed it to mwSize but still I don't have access to correct values of prhs[0].

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2012년 10월 21일
The "%d" format in mexPrintf does not match the type double. Better:
mexPrintf("(%d): [ %f ]\n", i, faces[i] );

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by