필터 지우기
필터 지우기

How to sortvalues in a variable based on another variable

조회 수: 1 (최근 30일)
RDG
RDG 2014년 7월 11일
답변: Chad Greene 2014년 7월 11일
Suppose, I have 2 cell variables:
A{1}=
46 25 35 25
22 1 11 1
22 1 11 1
46 25 35 25
B{1}=
3 4 5 6
3 7 5 8
3 2 5 2
3 8 5 9
I would like to sort the values in B based on the values in A (in ascending order) by row. I have provided an example of the output as follow:
resultantA{1}=
25 25 35 45
1 1 11 22
1 1 11 22
25 25 35 46
resultantB{1}=
4 6 5 3
7 8 5 3
2 2 5 3
8 9 5 3

답변 (1개)

Chad Greene
Chad Greene 2014년 7월 11일
It's nice that you have given an example, but I need help understanding how you have sorted things in your example.
The sort and sortrows functions will return indices which describe how A is sorted. Then you can sort B like Bsorted = B(ind).

카테고리

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