extracting a row from a matrix

조회 수: 3 (최근 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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by