Get matrix size from a pointer- MEX
Mostrar comentarios más antiguos
Hello folks,
I read the second variable in C++
#define D prhs[1]
double** *d = mxGetPr(D); // get the pointer
Now I want to get the size of D
int mySize = mxGetM(D);
cool...Now how can I get the size from the pointer d (not D)?
int mySize = mxGetM((const mxArray) d); // does not work
Thanks,
Respuestas (1)
Walter Roberson
el 24 de Ag. de 2015
You cannot do that. MATLAB can store multiple arrays as pointing to the same data, as long as all of the arrays have the same total number of elements. There is no one "size" for a data block.
P = rand(52,5);
Q = reshape(P, 13, 5, 4);
P and Q will have the same data pointer. R = reshape(Q, 13, 4, 5) would have the same data pointer too and probably makes more sense, but reshape() does not care about whether the reshape makes sense, only that the number of elements remains constant.
Categorías
Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!