Version:

Returns the indexes of all non-zero elements in a matrix.

Syntax

ind = findnz(a)
ind = findnz(a, n)
ind = findnz(a, n, direction)
[i, j] = findnz(a)
[i, j] = findnz(a, n)
[i, j] = findnz(a, n, direction)
[i, j, c] = findnz(a)
[i, j, c] = findnz(a, n)
[i, j, c] = findnz(a, n, direction)
Legacy name: find

a

Vector or matrix of any data type.

n

Number of matches to return. n is a positive integer. The default is to return all matches.

direction

Direction to search for matches. direction is a string, that accepts the following values.

 'first' (default) Returns the first n matches. 'last' Returns the last n matches.

ind

Linear indexes of all non-zero elements of a. a is considered a long vector a(:) if only one output is required. ind is a row vector if a is a row vector, otherwise ind is a column vector.

i

First indexes of all non-zero elements of a. i is a column vector.

j

Second indexes of all non-zero elements of a. j is a column vector.

c

All non-zero elements of a. c is a column vector.