I have a matrix and I want to find the maximum value in each column, then find the index of the row of that maximum value.
3 Answers
0
votes
0
votes
0
votes
Another way to do this would be to use find
. You can output the row and column of the maximum element immediately without invoking max
twice as per your question. As such, do this:
%// Define your matrix
A = ...;
% Find row and column location of where the maximum value is
[maxrow,maxcol] = find(A == max(A(:)));
Also, take note that if you have multiple values that share the same maximum, this will output all of the rows and columns in your matrix that share this maximum, so it isn't just limited to one row and column as what max
will do.