How do we sort one column of an alpha-numeric table and make the other columns to adjust accordingly?
이전 댓글 표시
INTRO: I import an alpha-numeric table A with the commands below:
fid = fopen('TEST_SORT.txt');
A= textscan(fid,'%f %f %s');
fclose(fid);
A=
9 5 G
1 4 B
4 3 E
2 2 D
6 1 C
3 0 I
0 9 A
7 8 H
5 7 F
8 6 J
GOAL: (1) I want to sort the rows of column 1 ascending and wish that the rows of column 2 and 3 adjust according to the sorted column 1;
(2) I want to sort the rows of the alpha-numeric column 3 and wish that the columns 1 and 2 adjust according to the sorted column 3.
PROBLEM: If I write
B=sort(A,1);
I obtain the following error:
Error using sort
DIM and MODE arguments not supported for cell arrays.
I read the documentation of sorting but it was not clear how the instructions apply to this specific situation.
I wonder if someone could help me to fix this problem.
Thank you in advance for your attention
Emerson
채택된 답변
추가 답변 (1개)
Thomas
2012년 10월 5일
I guess this is what you need
a={9 5 'G'
1 4 'B'
4 3 'E'
2 2 'D'
6 1 'C'
3 0 'I'
0 9 'A'
7 8 'H'
5 7 'F'
8 6 'J'}
%to sort according to column 1
out1=sortrows(a,1)
%to sort according to column 3
out2=sortrows(a,3)
댓글 수: 1
Emerson De Souza
2012년 10월 5일
카테고리
도움말 센터 및 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!