K = find(M)
[R, C] = find(M)
[R, C, V] = find(M)
K = find(M, N)
[R, C] = find(M, N)
[R, C, V] = find(M, N)
K = find(M, N, D)
[R, C] = find(M, N, D)
[R, C, V] = find(M, N, D)
| Parameter | Description |
|---|---|
| M | a scalar, vector, matrix, multidimensional array, or sparse matrix. |
| N | positive integer scalar value, or Inf, indicating the number of nonzeros to find. |
| D | direction: 'first' (default) or 'last'. The value is case-insensitive. |
| Parameter | Description |
|---|---|
| K | indices to nonzero elements (vector). |
| R | row subscripts (vector). |
| C | column subscripts (vector). |
| V | nonzero elements of M (vector). |
K = find(M) returns a vector with the linear indices of each nonzero element of M.
find(M, Inf) returns all nonzero indices and can be combined with the direction argument.
For sparse input, find accepts double, single, logical, complex double, and complex single sparse matrices. Stored zero values are ignored; only entries whose value is actually nonzero are returned.
With three outputs, V keeps the value class of the input sparse matrix, including single and logical values.
M = rand(4, 3, 5);
[R, C, V] = find(M > 0.9)
M(R(1),C(1),V(1))
K = find([0 2 0 3], Inf, 'LAST')
S = sparse([1 2 1 2], [1 1 2 2], single([0 -0 complex(0, 0) complex(0, 2)]), 2, 2, 4);
[R, C, V] = find(S)
| Version | Description |
|---|---|
| 2.0.0 | extended sparse single and complex single support |
| 1.0.0 | initial version |