find
Find indices and values of nonzero elements
Description
returns a vector containing the linear indices of each nonzero element in array
k
= find(X
)X
.
If
X
is a vector, thenfind
returns a vector with the same orientation asX
.If
X
is a multidimensional array, thenfind
returns a column vector of the linear indices of the result.
Examples
Input Arguments
Output Arguments
More About
Tips
To find array elements that meet a condition, use
find
in conjunction with a relational expression. For example,find(X<5)
returns the linear indices to the elements inX
that are less than5
.To directly find the elements in
X
that satisfy the conditionX<5
, useX(X<5)
. Avoid function calls likeX(find(X<5))
, which unnecessarily usefind
on a logical matrix.When you execute
find
with a relational operation likeX>1
, it is important to remember that the result of the relational operation is a logical matrix of ones and zeros. For example, the command[row,col,v] = find(X>1)
returns a column vector of logical1
(true
) values forv
.The row and column subscripts,
row
andcol
, are related to the linear indices ink
byk = sub2ind(size(X),row,col)
.
Extended Capabilities
Version History
Introduced before R2006a