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 Kommentare

Azzi Abdelmalek
Azzi Abdelmalek am 29 Jan. 2014
Bearbeitet: Azzi Abdelmalek am 29 Jan. 2014
Is it a cell array ?
Something like this
M={'(1,A1)'
'(1,B1)'
'(1,C1)'
'(1,A2)'
'(1,B2)'
'(1,C2)'
'(1,A3)'
'(1,B3)'
'(1,C3)'}
If the brackets are not part of your data, please remove them
andrew
andrew am 29 Jan. 2014
Yes it is a cell array
Walter Roberson
Walter Roberson am 29 Jan. 2014
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 ?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 29 Jan. 2014

0 Stimmen

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)

Kategorien

Gefragt:

am 29 Jan. 2014

Beantwortet:

am 29 Jan. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by