MATLAB Application Program Interface | Search  Help Desk |
mxGetDimensions | Examples See Also |
Get a pointer to the dimensions array
#include "matrix.h" const int *mxGetDimensions(const mxArray *array_ptr);array_ptr
mxArray
.
The address of the first element in a dimension array. Each integer in the dimensions array represents the number of elements in a particular dimension. The array is not NULL
-terminated.
Use mxGetDimensions
to determine how many elements are in each dimension of the mxArray
that array_ptr
points to. Call mxGetNumberOfDimensions
to get the number of dimensions in the mxArray
.
Consider a MEX-file named GetSize
that returns the size of each dimension of an input mxArray
:
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[]) { int number_of_dims, c; const int *dim_array; number_of_dims = mxGetNumberOfDimensions(prhs[0]); dim_array = mxGetDimensions(prhs[0]); for (c=0; c<number_of_dims; c++) mexPrintf("%d\n", *dim_array++); }In MATLAB, create a variable named
my4d,
then pass my4d
to GetSize
:
>> my4d = rand(3,5,2,4);Call
GetSize
to return the size of each dimension in my4d
:
>> GetSize(my4d) 3 5 2 4
mxGetNumberOfDimensions