This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Handle Sparse Arrays

The MATLAB® 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 manipulate ir and jc, two of the parameters associated with sparse arrays. For more information on how MATLAB stores sparse arrays, see The MATLAB Array.

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 = eye(5)
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 fulltosparse to produce the corresponding sparse matrix.

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

Related Topics