Find the last position of maximum value in a Matrix
이전 댓글 표시
Hello, I try to find the position and the value of a maximum in a Matrix (or in a vektor). There are several positions for the maximas and the function [C,I] = max(...) just return the first, but I need the last position. exists a method to find the last maximum?
채택된 답변
추가 답변 (2개)
Azzi Abdelmalek
2013년 11월 27일
x=[1 2 3 0 3];
[ii,jj]=max(fliplr(x));
idx=numel(x)-jj+1
Bradley Stiritz
2021년 1월 31일
@Wayne, is your solution vulnerable to rounding error, with floating-point input? In general, might it not be safer to use something like the following--?
epsilon = 0.0001;
I = find(abs(x-maxval)<epsilon,1,'last');
@Azzi, very clever solution but is it not hard-coded for row vectors? In order to handle column vectors as well, shouldn't the 2nd line be something like the following--?
[ii,jj]=max(fliplr(x(:)'));
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!