Mathematics | ![]() ![]() |
The find Function and Sparse Matrices
For any matrix, full or sparse, the find
function returns the indices and values of nonzero elements. Its syntax is
[i,j,s] = find(S)
find
returns the row indices of nonzero values in vector i
, the column indices in vector j
, and the nonzero values themselves in the vector s
. The example below uses find
to locate the indices and values of the nonzeros in a sparse matrix. The sparse
function uses the find
output, together with the size of the matrix, to recreate the matrix.
[i,j,s] = find(S) [m,n] = size(S) S = sparse(i,j,s,m,n)
![]() | Viewing Sparse Matrices Graphically | Example: Adjacency Matrices and Graphs | ![]() |