Grammar:
IND = Find (x)
ind = Find (x, k) ind = Find (x, K, ' a '
)
ind = Find (x, K, "last")
[Row,col] = find (x, ...)
[Row,col,v] = Find (X, ...)
IND = FIND (x) queries the position of a non-0 element, and if X is a row vector, returns a row vector, otherwise, returns a column vector. If x is all 0 elements or an empty array, an empty array is returned.
[Row,col V] = find (X, ...) Query the rows and columns of an element that satisfies a certain condition
X is generally a logical expression, such as x>5.
Where row returns the position of the element row that satisfies the condition
Col returns the position of the column of the element that satisfies the condition
V if x is a logical expression, returns a logical array, which generally returns a unit column vector if there is an element that satisfies the requirement. If no element satisfies the requirement, an empty vector is returned.
Examples:
>> a= Magic (4) A = 2 3 (5) 8 9 7 6 4 1
>> [r,c,v]= Find (A>12)
r =
1
4
4
1
c = 1 2 3 4
v =
1
1
1 1
Examples:
>> x = [3 0 0; 0 0 7; 0 0 1] x = 3 0 0 0 0 7 0 0 1
>> [R,c,v]=find (x)
r =
1
2
3
c =
1
3
3
v =
3 7 1
>> x = [3 2 0;-5 0 + 7; 0 0 1];
>> [~,~,v]=find (x~=0)
v =
1
1
1
1
1
>> [~,~,v]=find (x)
v =
3
-5
2
7
1
Compare the difference between v returned by the two calling methods:
[r,c,v]= Find (A>12): v Returns a unit column vector
[R,c,v]=find (x): v Returns a column vector consisting of the element that satisfies the requirement
IND = Find (X, K, ' a ')
IND = Find (X, K, ' last ')
Returns the position of the row and column of K for the element that satisfies the condition X, where ' first ' indicates that ' last ' represents the beginning of the final element from the beginning.
Examples
>> a=[4 0 3 1 0 9 2];
>> find (a,3, ' a ')
ans =
1 3 4
>> find (a,3, ' last ')
ans =
4 6 7