Returns a vector that contains the indicies of all non-zero elements in an array. The usage is
y = find(x)
The indices returned are generalized column indices, meaning that if
the array x is of size [d1,d2,...,dn], and the
element x(i1,i2,...,in) is nonzero, then y
will contain the integer
Some simple examples of its usage, and some common uses of find in FreeMat programs.
--> a = [1,2,5,2,4];
--> find(a==2)
ans =
<uint32> - size: [2 1]
Columns 1 to 1
2
4
Here is an example of using find to replace elements of A that are 0 with the number 5.
--> A = [1,0,3;0,2,1;3,0,0]
A =
<int32> - size: [3 3]
Columns 1 to 3
1 0 3
0 2 1
3 0 0
--> n = find(A==0)
n =
<uint32> - size: [4 1]
Columns 1 to 1
2
4
6
9
--> A(n) = 5
A =
<int32> - size: [3 3]
Columns 1 to 3
1 5 3
5 2 1
3 5 5
Incidentally, a better way to achieve the same concept is:
--> A = [1,0,3;0,2,1;3,0,0]
A =
<int32> - size: [3 3]
Columns 1 to 3
1 0 3
0 2 1
3 0 0
--> A(A==0) = 5
A =
<int32> - size: [3 3]
Columns 1 to 3
1 5 3
5 2 1
3 5 5