currently the files are orderd like this, the value increasing by 30 each time up to 1830:
however, with the code i've used, matlab orders the files like this:
is there any way i can sort the files to match the original?
dirName = pwd;
files = dir( fullfile(dirName,'*.txt') );
files = {files.name}';
files = sortrows(files,'ascend')

 채택된 답변

Stephen23
Stephen23 2022년 4월 11일
편집: Stephen23 2022년 4월 11일

0 개 추천

P = pwd;
S = dir(fullfile(P,'*.txt'));
C = {S.name};
[~,X] = sort(str2double(regexp(C,'\d+','match','once')));
C = C(X);

댓글 수: 1

Or
C = string{S.name});
[~,X] = sort(double(extractBetween(C,"_",".txt")));
C = C(X);
for those of us who can't get our minds around patterns and regexp.

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

추가 답변 (1개)

DGM
DGM 2022년 4월 11일

0 개 추천

댓글 수: 1

james Green
james Green 2022년 4월 11일
thanks that works perfectly, however this is part of an uni assignment which i can only subbmit one .m file for, so i dont think i can use this. im not very familiar with file exchange is there a way to get around this.

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

카테고리

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

태그

질문:

2022년 4월 11일

댓글:

2022년 4월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by