Sort cell array columns by two dimensions

I want to sort the columns of a cell array along the first two rows.
The array has this form (the top row is already sorted):
array = {'A' 'A' 'B' 'B' 'B' 'C' 'C'; ...
1 0.1 1 0.1 0.5 1 0.1; ...
2 3 2 4 5 2 3}
And I would like the output to be in this form:
array = {'A' 'A' 'B' 'B' 'B' 'C' 'C'; ...
0.1 1 0.1 0.5 1 0.1 1; ...
3 2 4 5 2 3 2}
Thanks in advance!

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 1월 10일
편집: Azzi Abdelmalek 2015년 1월 10일

1 개 추천

array = {'A' 'A' 'B' 'B' 'B' 'C' 'C'
1 0.1 1 0.1 0.5 1 0.1
2 3 2 4 5 2 3}
array=sortrows(array',[1,2])'

추가 답변 (1개)

Star Strider
Star Strider 2015년 1월 10일

1 개 추천

This seems to work:
array = {'A' 'A' 'B' 'B' 'B' 'C' 'C'; ...
1 0.1 1 0.1 0.5 1 0.1; ...
2 3 2 4 5 2 3};
B = sortrows(array', [1 2])'
and produces:
B =
'A' 'A' 'B' 'B' 'B' 'C' 'C'
[0.1] [1] [0.1] [0.5] [1] [0.1] [1]
[ 3] [2] [ 4] [ 5] [2] [ 3] [2]

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2015년 1월 10일

답변:

2015년 1월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by