To get it's location as well, accept both outputs of max:
[maxValue, linearIndexesOfMaxes] = max(A(:));
Note that there can be the max value at more than one location. To get the rows and columns (instead of linear indexes), you can use ind2subs() or find():
This should be upvoted and/or somehow appear closer to the chosen answer, as M = max(A,'all') seems not to work at all in R2018b+ (returning the entire matrix).
M = max(A(:)) seems to work in R2018b+ and presumably universally.
The [] as the second input is required when you want to specify a dimension, including 'all'. The function call max(A, 'all') only works if A and 'all' are compatibly sized.
No, you don't need to include multiple calls to max. See the accepted Answer for approaches that call max only once regardless of how many dimensions the input argument has.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
2 Comments
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/47428-to-find-the-maximum-value-in-a-matrix#comment_97632
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/47428-to-find-the-maximum-value-in-a-matrix#comment_97632
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/47428-to-find-the-maximum-value-in-a-matrix#comment_350996
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/47428-to-find-the-maximum-value-in-a-matrix#comment_350996
Sign in to comment.