Documentation

Manipulate Multidimensional Numerical Arrays

You can manipulate multidimensional numerical arrays by using mxGetData and mxGetImagData. These functions return pointers to the real and imaginary parts of the data stored in the original multidimensional array. The example, findnz.c, takes an N-dimensional array of doubles and returns the indices for the nonzero elements in the array.

Build the example.

mex findnz.c

Create a sample matrix.

matrix = [ 3 0 9 0; 0 8 2 4; 0 9 2 4; 3 0 9 3; 9 9 2 0]
matrix =
     3     0     9     0
     0     8     2     4
     0     9     2     4
     3     0     9     3
     9     9     2     0

findnz determines the position of all nonzero elements in the matrix.

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

See Also

|

Related Examples

Was this topic helpful?