who to sort pairs of arrays in the same order one based on the other?

조회 수: 7 (최근 30일)
Hello MATLAB experts, I have asked many questions and I really appreciate your prompt responses. My New question is that, I have set of pairs of arrays. In each pair, one array has numbers from 0 to 20 (but not arranged) for one variable values and the other array have decimal values presents the other variable values. I want to sort the elements in the first array in ascending order (0,1,2,...20) but at the same time I want to sort the other accompanied array of the pair in the same order (indices sorted similarly).

채택된 답변

Walter Roberson
Walter Roberson 2015년 11월 8일
[firstsordered, firstsortorder] = sort(first_array);
secondsorted = second_array(firstsortorder);

추가 답변 (1개)

Abdulaziz Abutunis
Abdulaziz Abutunis 2015년 11월 8일
[firstsordered, firstsortorder] = sort(first_array); sometimes gave a values after sorting i just used the following and it does work very well firstsortorder = sort(first_array); secondsorted = second_array(firstsortorder);
Thanks again
  댓글 수: 1
Abdulaziz Abutunis
Abdulaziz Abutunis 2015년 11월 8일
Sorry, you are right i was repeating the same name [firstsordered, firstsordered] instead of [firstsordered, firstsortorder].
Thanks

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

카테고리

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