I'm trying to find the maximum value of a certain column in a matrix. I want to find both the maximum value and the index of the row in which it is. How can I do this?
解决方案
max command can find both the maximal value and its index.
Here's an example:
>> A = randn(10,3)
A =
0.8884 -0.10224 -0.86365
-1.1471 -0.24145 0.077359
-1.0689 0.31921 -1.2141
-0.8095 0.31286 -1.1135
-2.9443 -0.86488 -0.0068493
1.4384 -0.030051 1.5326
0.32519 -0.16488 -0.76967
-0.75493 0.62771 0.37138
1.3703 1.0933 -0.22558
-1.7115 1.1093 1.1174
>> [maxVal maxInd] = max(A)
maxVal =
1.4384 1.1093 1.5326
maxInd =
6 10 6