| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
#include "matrix.h" int mxSetDimensions(mxArray *pm, const mwSize *dims, mwSize ndim);
integer*4 mxSetDimensions(pm, dims, ndim) mwPointer pm mwSize dims, ndim
Pointer to an mxArray
Dimensions array. Each element in the dimensions array contains the size of the array in that dimension. For example, in C, setting dims[0] to 5 and dims[1] to 7 establishes a 5-by-7 mxArray. In Fortran, setting dims(1) to 5 and dims(2) to 7 establishes a 5-by-7 mxArray. In most cases, there should be ndim elements in the dims array.
Number of dimensions
0 on success, and 1 on failure. mxSetDimensions allocates heap space to hold the input size array. So it is possible (though extremely unlikely) that increasing the number of dimensions can cause the system to run out of heap space.
Call mxSetDimensions to reshape an existing mxArray. mxSetDimensions is similar to mxSetM and mxSetN; however, mxSetDimensions provides greater control for reshaping mxArrays that have more than two dimensions.
mxSetDimensions does not allocate or deallocate any space for the pr or pi arrays. Consequently, if your call to mxSetDimensions increases the number of elements in the mxArray, you must enlarge the pr (and pi, if it exists) arrays accordingly.
If your call to mxSetDimensions reduces the number of elements in the mxArray, you can optionally reduce the size of the pr and pi arrays using mxRealloc.
Any trailing singleton dimensions specified in the dims argument are automatically removed from the resulting array. For example, if ndim equals 5 and dims equals [4 1 7 1 1], the resulting array is given the dimensions 4-by-1-by-7.
See mxsetdimensions.c in the matlabroot/extern/examples/mx folder .
mxGetNumberOfDimensions, mxSetM, mxSetN, mxRealloc
![]() | mxSetData (C and Fortran) | mxSetField (C and Fortran) | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |