MATLAB Application Program Interface Reference Help Desk

mxSetDimensions

Purpose

Modify the number of dimensions and/or the size of each dimension

C Syntax

Arguments

array_ptr

Pointer to an mxArray.

ndims

The desired number of dimensions.

dims

The first element of an array of ints. Each element in the array holds the size of a particular dimension. The first element holds the number of elements in the first dimension (rows); the second element holds the number of elements in the second dimension, and so on.

Returns

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.

Description

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, then 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, then you can optionally reduce the size of the pr and pi arrays.

Examples

Create a populated 3-by-2 mxArray. Then, call mxSetDimensions to expand the mxArray to 4-by-3-by-2. Preserve the original 3-by-2 data as the first page of the expanded mxArray.

For an additional example, see mxSetDimensions.c in the mx subdirectory of the examples directory.

See Also

mxGetNumberOfDimensions, mxSetM, mxSetN



[ Previous | Help Desk | Next ]