Using the C Math Library | ![]() ![]() |
Determining Array Shape
To determine the number of dimensions of an array, use the mlfNdims()
routine. This code uses mlfNdims()
to get the number of dimensions of a 2-by-3-by-2 array.
mxArray *A = NULL; mxArray *ndims = NULL; /* Create three-dimensional array */ mlfAssign(&A, mlfOnes(mlfScalar(2), mlfScalar(3), mlfScalar(2), NULL)); /* Determine dimensions */ mlfAssign(&ndims, mlfNdims( A )); mlfFprintf(mlfScalar(1), mxCreateString("The array has %d dimensions"), ndims, NULL); mxDestroyArray(A); mxDestroyArray(ndims);
This code outputs the value 3
, indicating that the array C
is a three-dimensional array.
![]() | Determining Array Size | Managing Array Memory | ![]() |