Effacer les filtres
Effacer les filtres

How do I get both the minimum of a 2D matrix and it's indices?

59 vues (au cours des 30 derniers jours)
Emmy
Emmy le 6 Mai 2013
Commenté : Walter Roberson le 5 Juin 2017
Hello,
I have a 2D matrix, and I want to know the minimum and its indices. I normally use min(min(matrix)), and I found here that I can also use min(matrix(:)). But I couldn't find out how to also get the location of this found minimum?
Thanks in advance!
Emmy

Réponses (2)

Matt Kindig
Matt Kindig le 6 Mai 2013
Modifié(e) : Matt Kindig le 6 Mai 2013
minMatrix = min(matrix(:));
[row,col] = find(matrix==minMatrix);

Azzi Abdelmalek
Azzi Abdelmalek le 6 Mai 2013
Modifié(e) : Azzi Abdelmalek le 6 Mai 2013
M=[4 5 6;2 1 4;1 0 5]
[min_val,idx]=min(M(:))
[row,col]=ind2sub(size(M),idx)

Catégories

En savoir plus sur Data Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by