How do I get both the minimum of a 2D matrix and it's indices?
조회 수: 39 (최근 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!