Contents Previous Next Subchapters

Determining Indices Corresponding to Nonzero Elements
Syntax i = find(flag)
[ij] = find(flag)
[ijnz] = find(flag)
See Also find string , nnz

Description
Determines the indices that correspond to elements of flag that are not equal to zero. If flag is a row vector, the return values are row vectors. Otherwise the return values are column vectors. The length of the return values is equal to the number of elements of flag that are not equal to zero. The return values i and j have type integer and the return value nz has the same type as flag. The values i(k), j(k) and nz(k) all correspond to the k-th nonzero element of flag in column major order .

i = find(flag)
If only one return value is specified, the indices in i correspond to the column major ordering of the matrix flag.

[
ij] = find(flag)
If two or three return values are specified, the values in i correspond to the row indices and j correspond to the column indices of the matrix flag.

[
ijnz] = find(flag)
If three return values are specified, the values in nz are the elements of flag that are not equal to zero.

Example
If you enter
     find([1, 0, 1])
O-Matrix will reply
     [ 1 , 3 ]
If you enter
     x = [{0 , 1}, {0, 2}]
     find(x)
O-Matrix will reply
     {
     2
     4
     }