I was wondering how can I sort a cell array. I have a cell array that contains 'T1-001'to 'T1-058' and 'T2-001 to T2-058' and was wondering if I could sort it so that it can go something like this:
T1-001,T2-001,T1-002, T2-002, etc.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 18일

1 개 추천

If a is your cell array
b=reshape(a,numel(a)/2,2)'
out=b(:)

추가 답변 (2개)

Andrei Bobrov
Andrei Bobrov 2013년 10월 18일

1 개 추천

q = {'T1-001','T2-058','T1-235','T1-058','T2-001',' T1-045'};
q0 = regexp(q,'\d*','match');
q1 = str2double(cat(1,q0{:}));
[~,ii] = sortrows(q1,[2 1]);
out = q(ii);
Yatin
Yatin 2013년 10월 18일
편집: Yatin 2013년 10월 18일

0 개 추천

Hello Andrew,
This could be a possible solution to your problem.

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2013년 10월 18일

답변:

2013년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by