Unable to retrive C array in Matlab
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Jan
on 18 Mar 2013
Edited: Jan
on 18 Mar 2013
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?
More Answers (0)
See Also
Categories
Find more on Deploy to C++ Applications Using mwArray API (C++03) in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!