How can i know what is the n when the nth is the smallest or biggest

1 view (last 30 days)
How can i know what is the n when the nth is the smallest or biggest,for example
A=[10 2 3 4 50]
mimn=min(A)
I can use the min instruction to know what is the smallest value in the vector A,but how do i know the nth element is 2 in the A vector,i mean i want to know the "n" value.In this simple example,we can know the "second" element is the smallest value in this A vector,but if there is 10000 elements in A vector,how do i know what is the n when the nth is the smallest ?

Accepted Answer

Rik
Rik on 29 Mar 2019
If you mean the index of the minimum value, the documentation for the min function shows you how to find the index. A different example vector will make it clearer.
A=[10 100 2 3 4 50];
[mimn,index]=min(A)
%mimn=2
%index=3
% so the third position has the lowest value in the vector, that value being 2

More Answers (1)

Andrei Bobrov
Andrei Bobrov on 29 Mar 2019
[minvalue, n] = min(A);

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!