MATLAB Application Program Interface Reference Help Desk

mxCreateSparse

Purpose

Create a 2-dimensional unpopulated sparse mxArray

C Syntax

Arguments

m

The desired number of rows.

n

The desired number of columns.

nzmax

The number of elements that mxCreateSparse should allocate to hold the pr, ir, and, if ComplexFlag is mxCOMPLEX, pi arrays. Set the value of nzmax to be greater than or equal to the number of nonzero elements you plan to put into the mxArray, but make sure that nzmax is less than or equal to m*n.

ComplexFlag

Set this value to mxREAL or mxCOMPLEX. If the mxArray you are creating is to contain imaginary data, then set ComplexFlag to mxCOMPLEX; otherwise, set ComplexFlag to mxREAL.

Returns

A pointer to the created sparse mxArray on success; returns NULL on failure. The most likely reason for failure is insufficient free heap space. If that happens, try reducing nzmax, m, or n.

Description

Call mxCreateSparse to create an unpopulated sparse mxArray. The returned sparse mxArray contains no sparse information and cannot be passed as an argument to any MATLAB sparse functions. In order to make the returned sparse mxArray useful, you must initialize the pr, ir, jc, and (if it exists) pi array.

mxCreateSparse allocates space for

When you finish using the sparse mxArray, call mxDestroyArray to reclaim all its heap space.

Examples

Create a sparse mxArray of real data. Although the mxArray is 3-by-2, only four of the six elements are occupied by nontrivial data.

mxDestroyArray(array_ptr); For an additional example, see mxCreateSparse.c in the mx subdirectory of the examples directory.

See Also

mxDestroyArray, mxSetNzmax, mxSetPr, mxSetPi, mxSetIr, mxSetJc, mxComplexity



[ Previous | Help Desk | Next ]