Get matrix size from a pointer- MEX
3 次查看(过去 30 天)
显示 更早的评论
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,
0 个评论
回答(1 个)
Walter Roberson
2015-8-24
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Access Fortran Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!