Reorder a Cell arrays

Hi. I am using uiget with multiselect to perform an operation on several text files. I assign the cell aray fname as below.
[fname,pname]=uigetfile('*.txt','select the Miscall Matrix files', 'MultiSelect', 'on',startpname);
My text files are always number are always of the form *1.txt to **12.txt and it always puts the last file first in the cell array. Is there a quick way to reorder the cell array "fname" Thanks

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 7월 22일

0 개 추천

Yep. This is pretty common. You need to do some processing.
fname={'abc3.txt','abc2.txt','abc1.txt','abc10.txt','abc12.txt'};
Num=regexp(fname,'\d+','match');
Num=char(cellfun(@cell2mat,Num,'uni',false));
[Num,Index]=sort(str2num(Num));
fname=fname(Index)

추가 답변 (1개)

Jason
Jason 2011년 7월 22일

0 개 추천

OK, I think i can use
sort(fname)

댓글 수: 1

Jason
Jason 2011년 7월 22일
Nope didn't work it put 1,10,1,2,3,4... and so on.

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

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

질문:

2011년 7월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by