[a_sorted, a_order] = sort(A);
newB = B(a_order,:);
This is a few commands that I found on here and I am unsure of what the colon in the second line means. I am trying to sort a vector based on how I sorted another vector and I stumbled across the code above. does this accomplish what I am trying to do, and how do I use the colon in this case for future reference?

 채택된 답변

Image Analyst
Image Analyst 2022년 1월 28일

0 개 추천

Colon means "all". Since it's in the columns place of the matrix, B(a_order, :) means "take all columns of the rows specified by a_order).
This will sort the rows of B in exactly the same way vertically as the rows of A were sorted.

추가 답변 (0개)

카테고리

도움말 센터File 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