How to combine two matrices to one and sort the rows?

조회 수: 3 (최근 30일)
C Zeng
C Zeng 2012년 6월 5일
Hello, my question is given a matrix M, say 10*5 size and one 10*1 say n. I want to make a new matrix that combine those into one matrix say M_new(10*6 size), the first five columns come from M, and 6th column comes from n.
Afterwards, sort the rows from largest to smallest by the last entry, say the number in n. Is there a good code on this? Thanks.

채택된 답변

Oleg Komarov
Oleg Komarov 2012년 6월 5일
M_new = [M, n];
M_new = sortrows(M_new,6);
See sortrows() for details.
  댓글 수: 5
Oleg Komarov
Oleg Komarov 2012년 6월 5일
Yes, I always forget about the minus!!
C Zeng
C Zeng 2012년 6월 6일
Haha, I just found it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by