Equana

Back to Core Functions

find

Find indices of nonzero elements

Syntax

k = find(X)
k = find(X, n)
k = find(X, n, direction)

Description

Returns the linear indices of nonzero elements in X. Optionally returns only the first or last n indices.

Parameters

NameDescription
XInput array
n(optional)Number of indices to return
direction(optional)'first' (default) or 'last' - which indices to return

Returns

Vector of indices (1-based)

Examples

Try It
>> find([1 0 3 0 5])
1  3  5
Try It
>> find([1 0 3 0 5], 2)
1  3
Try It
>> find([1 0 3 0 5], 2, 'last')
3  5
Try It
>> A = [1 2 3 4 5]; find(A > 3)
4  5

See Also