Unable to retrive C array in Matlab

1 vue (au cours des 30 derniers jours)
Alok Pathak
Alok Pathak le 18 Mar 2013
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

Réponse acceptée

Jan
Jan le 18 Mar 2013
Modifié(e) : Jan le 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?
  1 commentaire
Alok Pathak
Alok Pathak le 19 Mar 2013
Thanks Jan for your reply.
I used the mlx function and it worked fine. This approach of mine to get the data as mxarray* into an mwArray didnt work quite well.
Sorry for some errors in the code. I was trying a lot of things in a deseparate hope to make it work. I did mean :
mwArray X1(X)
This is just a dummy code that I was trying, because the main data that I have is a uchar* , Although even with double*, I am getting the same problem.
what this dummy code should have done was pass on the data to a simple Justcheck.m which would only display the contents.
But instead of the matrix I got the display as 1.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Deploy to C++ Applications Using mwArray API (C++03) dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by