Handle Sparse Arrays in C MEX File - MATLAB & Simulink (original) (raw)

Main Content

The C Matrix API provides a set of functions that allow you to create and manipulate sparse arrays from within your MEX files. These API routines access and manipulateir and jc, two of the parameters associated with sparse arrays. For more information on how MATLABĀ® stores sparse arrays, see MATLAB Array in C/C++ Applications.

The example fulltosparseIC.c shows how to populate a sparse matrix.

Build the example.

mex -R2018a fulltosparseIC.c

Create a full, 5-by-5 identity matrix.

full = 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1

Call fulltosparseIC to produce the corresponding sparse matrix.

spar = fulltosparseIC(full)

spar = (1,1) 1 (2,2) 1 (3,3) 1 (4,4) 1 (5,5) 1

See Also

Topics