Unable to retrive C array in Matlab

1 visualización (últimos 30 días)
Alok Pathak
Alok Pathak el 18 de Mzo. de 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

Respuesta aceptada

Jan
Jan el 18 de Mzo. de 2013
Editada: Jan el 18 de Mzo. de 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 comentario
Alok Pathak
Alok Pathak el 19 de Mzo. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Deploy to C++ Applications Using mwArray API (C++03) en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by