Neil G
Neil G

Reputation: 33282

How do I get the index of the smallest element in an array in matlab?

How do I get the index of the smallest element in an array in matlab?

Upvotes: 3

Views: 15821

Answers (2)

Anycorn
Anycorn

Reputation: 51565

[C,I] = min(...) finds the indices of the minimum values of A, and returns them in output vector I. If there are several identical minimum values, the index of the first one found is returned.

Upvotes: 6

linuxuser27
linuxuser27

Reputation: 7353

Use the min() function with 2 output arguments. The first returned value will be the value, the second will be the index of that value.

Upvotes: 2

Related Questions