User`s manual
Examples of C MEX-Files
2-29
This example determines the position of all nonzero elements in the matrix.
Running the MEX-file on this matrix produces
nz = findnz(matrix)
nz =
1 1
4 1
5 1
2 2
3 2
5 2
1 3
2 3
3 3
4 3
5 3
2 4
3 4
4 4
Handling 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, refer to
the section, “The MATLAB Array” on page 1-6.
This example illustrates how to populate a sparse matrix.
/*==============================================================
* fulltosparse.c
* This example demonstrates how to populate a sparse
* matrix. For the purpose of this example, you must pass in a
* non-sparse 2-dimensional argument of type double.
* Comment: You might want to modify this MEX-file so that you can
* use it to read large sparse data sets into MATLAB.
*
* This is a MEX-file for MATLAB.
* Copyright (c) 1984-2000 The MathWorks, Inc.