开发者

Get the min row of a matrix in MATLAB

开发者 https://www.devze.com 2023-02-07 18:53 出处:网络
I have a matrix like: 1.000024.6914 2.000034.5679 3.000027.开发者_JAVA百科1605 4.000030.8642 5.000027.1605

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)),:)
0

精彩评论

暂无评论...
验证码 换一张
取 消