How do I get both the minimum of a 2D matrix and it's indices?
71 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
Matt Kindig
2013-5-6
编辑:Matt Kindig
2013-5-6
minMatrix = min(matrix(:));
[row,col] = find(matrix==minMatrix);
0 个评论
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 Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!