extracting a row from a matrix

2 ビュー (過去 30 日間)
Mahi Nazir
Mahi Nazir 2013 年 12 月 12 日
コメント済み: Mahi Nazir 2013 年 12 月 12 日
I want to extract a row from a matrix for which the last column element is largest. for example if my matrix is
1 2 3
1 1 4
2 1 2
3 2 5
my answer would be the last row 3 2 5 because 5 is the largest element in the last column. How do I do this please help.

採用された回答

Jan
Jan 2013 年 12 月 12 日
M = [1,2,3;1,1,4;2,1,2;3,2,5];
[~, max_idx] = max( M(:,end) );
max_row = M(max_idx,:);
  1 件のコメント
Mahi Nazir
Mahi Nazir 2013 年 12 月 12 日
Thanks! I did the same too.... was a little late in posting though.... Will accept your answer though :) cheers!

サインインしてコメントする。

その他の回答 (1 件)

Mahi Nazir
Mahi Nazir 2013 年 12 月 12 日
編集済み: Mahi Nazir 2013 年 12 月 12 日
I think I solved it, if my matrix is A
[C,I]=max(A(:,3)) %it will find the max in the last column and its index
row=A(I,:)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by