Contents Previous Next Subchapters Current Chapters-> align atod atoi char2dbl ntoa num2str str2num strreplace strclip clipstr low2up up2low dquote file2str pack unpack char2id reprow str2strdir sort sort3 psort psort3 mlmode_sort reverse flipud fliplr rot90 nonzeros find find2 find3 dec2hex hex2dec findstr whichrow Parent Chapters-> Omatrix6 stringssort find Search Tools-> contents reference index search

Determining Indices Corresponding to Nonzero Elements
 Syntax i` = find(`flag`)` `[`i`, `j`] = find(`flag`)` `[`i`, `j`, `nz`] = 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. ``` [```i`, `j`] = 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. ``` [```i`, `j`, `nz`] = 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      } ```