MATLAB: Find the last position of maximum value in a Matrix

indexlast maximummatrixmaximum

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?

Best Answer

You can use find() with the 'last' argument:
x = randi([1 10],100,1);
maxval = max(x);
I = find(x==maxval,1,'last');
Or for a matrix:
X = randi([1 10],20,20);
maxval = max(X(:));
[I,J] = find(X==maxval,1,'last');