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

1 回表示 (過去 30 日間)
yang-En Hsiao
yang-En Hsiao 2019 年 3 月 29 日
回答済み: Andrei Bobrov 2019 年 3 月 29 日
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 ?

採用された回答

Rik
Rik 2019 年 3 月 29 日
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

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2019 年 3 月 29 日
[minvalue, n] = min(A);

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by