find
Find the indices of nonzero elements in an array.
(ind)=find(a)
Inputs
a Any numeric array or, more, typically, logical array.
Outputs
ind Array of indices of the nonzero elements of the inputs.


Description
The elements of the outputs are not subsrcipts, but indices, so that a[find(a)] returns the vector containing nonzero elements of the input. To obtain the corresponding subscripts, use the function ind2sub.

Note that find returns indices and and not subscripts.


Example
>>a[1:2,1:2,1]=[2 0; 0 4]
>>a[1:2,1:2,2]=[4 5; 0 -3]
>>a
[:, :, 1]
         2         0
         0         4
[:, :, 2]
         4         5
         0        -3

>>find(a)
          1
          4
          5
          7
          8

>>a(find(a))
          2
          4
          4
          5
         -3