Skip to content

find

builtin · libnexusinterp/corefcn/find-proprietary.cc

: idx = find (x)
: idx = find (x, n)
: idx = find (x, n, direction)
: [row, col] = find (…)
: [row, col, val] = find (…)
: [row, col, val, m, n] = find (…)

Locate the nonzero elements of x.

With one output the column-major linear indices are returned; with two the row and column subscripts; with three the nonzero values as well. For a row vector the results are rows, otherwise columns. For arrays of more than two dimensions the column index runs over all trailing dimensions.

n, a nonnegative integer or Inf, limits the number of results. direction is "first" (default) to keep the first n matches or "last" to keep the last n; it is not case sensitive. NaN counts as nonzero.