Unable to retrive C array in Matlab
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi Friends
I am working on a C++ Project with various functions performed by Matlab C++ shared library. I need to pass an array to the Matlab code. Here's an example of how I', doing it :
if true
double mat[] = {
11, 21,
12, 22,
13, 23,
14, 24
};
uchar *mat2 ;
//mat2 = (uchar*) malloc(sizeof(uchar));
mat2 = (uchar*) &mat[0];
// Allocate memory. mxCOMPLEX for complex array
mxArray* X = mxCreateDoubleMatrix(nRow, nCol, mxREAL);
// Assign
memcpy(mxGetPr(X), mat2, nRow*nCol*sizeof(double));
// When using the mex -largeArrayDims switch, mwSize is equivalent to size_t
double *xValues = mxGetPr(X);
// for(int i =0;i<8;i++) Trial 1
// {
// qDebug()<<xValues[i];}
mwArray X1(X);
justcheck(X1);
end
The Problem is that when I open up the trial 1 comment, I do get the data as such. But when I send it to the function "justcheck(), I get that X1 has only one element which is equal to 1.
Can you please help me find out my error?
Thank you
Regards Alok
댓글 수: 0
채택된 답변
Jan
2013년 3월 18일
편집: Jan
2013년 3월 18일
mwArray(X1(xValues)) looks strange. xValues is the size_t integer pointer to the values of X, such that X1 should be a scalar from an integer according to the documentation. Do you mean:
mwArray X1(X)
? Please note, that it is hard to suggest an improvement only based on the failing code. At least it has to be explained, what the code should achieve.
The conversion of the pointer to mat2 to an uchar * looks more complicated than necessary: why not using double *mat directly?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Deploy to C++ Applications Using mwArray API (C++03)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!