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

71 ビュー (過去 30 日間)
Emmy
Emmy 2013 年 5 月 6 日
コメント済み: Walter Roberson 2017 年 6 月 5 日
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

回答 (2 件)

Matt Kindig
Matt Kindig 2013 年 5 月 6 日
編集済み: Matt Kindig 2013 年 5 月 6 日
minMatrix = min(matrix(:));
[row,col] = find(matrix==minMatrix);

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 6 日
編集済み: Azzi Abdelmalek 2013 年 5 月 6 日
M=[4 5 6;2 1 4;1 0 5]
[min_val,idx]=min(M(:))
[row,col]=ind2sub(size(M),idx)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by