I have a matrix like:
1.0000 24.6914
2.0000 34.5679
3.0000 27.开发者_JAVA百科1605
4.0000 30.8642
5.0000 27.1605
6.0000 25.9259
7.0000 14.6914
8.0000 23.4568
9.0000 25.9259
10.0000 22.2222
... ...
23.0000 23.4568
I know that if I use
min( MATRIX(:,2) )
I get the min value of column 2, but how can I get the min value and the corresponding value from the first column? From the example, my desired result would be:
7.0000 14.6914
You first need to get the index to the min value:
[minVal, minInd] = min( MATRIX(:,2) );
And then access the 1st row at that index:
MATRIX(minInd,1);
A little less elegant syntax would be:
MATRIX(find(MATRIX(:,2)==min(MATRIX(:,2)),1));
MATRIX(MATRIX(:,2)==min(MATRIX(:,2)),:)
精彩评论