Example array
test = {'PC','S','PO';84938,'O','Q34ef3';84548,'P','Q34g53';84248,'O','Q37h93';};
test =
'PC' 'S' 'PO'
[84938] 'O' 'Q34ef3'
[84548] 'P' 'Q34g53'
[84248] 'O' 'Q37h93'
Thank you in advance
Chmical
sort by first col (trsnforming num2str).
sortrows(cellfun(@num2str, test(2:end,:),'un',0),1)
If you have the statistics tb use the dataset object.
Oleg
Thank you Oleg works great. One more question... If I sort by the second column I used the same code just replacing the 1 with a 2. My question is: Do I have to do that since the second column is already a string?
Chmical
The point is that sort and sortrows accept only numeric inputs or cell arrays of strings.
There are other ways to sort a cell array, the best woul be to use a dataset object:
dt = dataset({[test{2:end,1}].','PC'},{test(2:end,2),'S'},{test(2:end,3),'PO'})
ans =
PC S PO
84938 'O' 'Q34ef3'
84248 'O' 'Q37h93'
84548 'P' 'Q34g53'
sortrows(dt,'S')
Otherwise you can extract the column PC (only its values) convert to double, sort it, take the idx and use it to sort te wole test cell array.
Oleg
Thank you again for the help...