필터 지우기
필터 지우기

Sort cell according to one column of the cell

조회 수: 116 (최근 30일)
Maria
Maria 2014년 8월 13일
답변: Andrei Bobrov 2014년 8월 13일
I have a cell type variable A with 500000 rows and 3 columns. See example below:
C1 C2 C3 C4
A={1994 'AACE' 2071 2
1998 'DFE' 7843 4
1999 'HC' 2071 4
1995 'JOP' 7843 4
1995 'IAC' 2071 2
I would like to sort this variable first by the C3 and then by C1. So I would have:
C1 C2 C3 C4
A={1994 'AACE' 2071 2
1995 'IAC' 2071 2
1999 'HC' 2071 4
1995 'JOP' 7843 4
1998 'DFE' 7843 4
I tried the follwoing code, but I am not being successful:
[~,i1]=sort(A(:,3)); %sort by column 3 A=A(i1,:);
[~,i1]=sort(A(:,1)); %sort by column 1 next A=A(i1,:);

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 8월 13일
out = sortrows(A,[3,1]);

추가 답변 (0개)

카테고리

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