How to sort the components of a vector?

조회 수: 4 (최근 30일)
Andre Ged
Andre Ged 2016년 2월 19일
편집: Stephen23 2016년 2월 19일
How can i sort the components of a vector in increasing order?

채택된 답변

Stephen23
Stephen23 2016년 2월 19일
편집: Stephen23 2016년 2월 19일
  댓글 수: 2
Andre Ged
Andre Ged 2016년 2월 19일
Thank you! Another little question. If every elements of that vector refers to a row of a matrix, is there a way to sort the rows of this matrix like the vector? I hope it is well explained!
Stephen23
Stephen23 2016년 2월 19일
편집: Stephen23 2016년 2월 19일
Use the second output of sort as indices for the matrix rows:
[newvec,idx] = sort(vec)
out = mat(idx,:)
This will sort the matrix rows into the same order as the vector is sorted.

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

추가 답변 (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