フィルターのクリア

How to sortvalues in a variable based on another variable

2 ビュー (過去 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 Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by