MATLAB Application Program Interface
  Go to function:
    Search    Help Desk 
mxSetN    Examples   See Also

Set the number of columns

C Syntax

Arguments

array_ptr
  Pointer to an mxArray.

n
  The desired number of columns.

Description

Call mxSetN to set the number of columns in the specified mxArray. The term "columns" always means the second dimension of a matrix. Calling mxSetN forces an mxArray to have two dimensions. For example, if array_ptr points to an mxArray having three dimensions, calling mxSetN reduces the mxArray to two dimensions.

You typically use mxSetN to change the shape of an existing mxArray. Note that mxSetN does not allocate or deallocate any space for the pr, pi, ir, or jc arrays. Consequently, if your calls to mxSetN and mxSetM increase the number of elements in the mxArray, then you must enlarge the pr, pi, ir, and/or jc arrays.

If your calls to mxSetM and mxSetN end up reducing the number of elements in the mxArray, then you may want to reduce the size of the pr, pi, ir, or jc arrays in order to reduce heap space usage. However, reducing the size is not mandatory.

Examples

Consider a 3-by-3 mxArray containing

10
14
20
12
17
22
13
18
23

Suppose you enlarge the mxArray to 4-by-4 but preserve the positions of the original 3-by-3 to yield an mxArray containing

10
14
20
0
12
17
22
0
13
18
23
0
0
0
0
0

The code to create the original 3-by-3 mxArray and the expanded 4-by-4 mxArray is

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

See Also

mxGetM, mxGetN, mxSetM



[ Previous | Help Desk | Next ]