Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
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 ?

Réponse acceptée

Rik
Rik le 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

Plus de réponses (1)

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

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by