필터 지우기
필터 지우기

how to sort rows

조회 수: 2 (최근 30일)
andrew
andrew 2014년 1월 29일
답변: Azzi Abdelmalek 2014년 1월 29일
I have a dataset with the following in a column with data
  • (1,A1)
  • (1,B1)
  • (1,C1)
  • (1,A2)
  • (1,B2)
  • (1,C2)
  • (1,A3)
  • (1,B3)
  • (1,C3)
How do I sort the column so that the out come is:
  • (1,A1)
  • (1,A2)
  • (1,A3)
  • (1,B1)
  • (1,B2)
  • (1,B3)
  • (1,C1)
  • (1,C2)
  • (1,C3)
  댓글 수: 3
andrew
andrew 2014년 1월 29일
Yes it is a cell array
Walter Roberson
Walter Roberson 2014년 1월 29일
Is it a cell array of strings, or is it an N x 2 cell array with the first column numeric and the second column something else ?

댓글을 달려면 로그인하십시오.

답변 (2개)

Amit
Amit 2014년 1월 29일

Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 29일
M={'(1,A1)'
'(1,B1)'
'(1,C1)'
'(1,A2)'
'(1,B2)'
'(1,C2)'
'(1,A3)'
'(1,B3)'
'(1,C3)'}
%M='(1,A1)'
c1=cellfun(@(x) x{1},regexp(M,'(?<=\().+(?=\,)','match'),'un',0)
c2=cellfun(@(x) x{1},regexp(M,'(?<=\,).+(?=\))','match'),'un',0)
[idx,idx]=sort(c2)
out=M(idx)

카테고리

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