필터 지우기
필터 지우기

make matlab read the files in order?

조회 수: 3 (최근 30일)
Tesla
Tesla 2020년 11월 4일
편집: Stephen23 2021년 4월 18일
I am using a code to read and calculate mass center. but the code read file with this oder:
Now reading C:\Users\shape_01.dat
Now reading C:\Users\shape_010.dat
Now reading C:\Users\shape_0100.dat
Now reading C:\Users\hape_0101.dat
so i get wrong orders for my output results.
because i need matlab to process my file in normal order: 1 2 3 4 4 5 ...
please is there any suggestion how to solve that?
  댓글 수: 2
Stephen23
Stephen23 2020년 11월 4일
@RBC MAN: are those binary numbers?
Or are they decimal numbers from which you happen to have only shown numbers using the digits 0 and 1 ?
Tesla
Tesla 2020년 11월 4일
Not binary, they are decimal, I just share the first 4 file, i have in total 501 files.
indeed it looks like that
Now reading C:\Users\shape_01.dat
Now reading C:\Users\shape_010.dat
Now reading C:\Users\shape_0100.dat
Now reading C:\Users\shape_0101.dat
Now reading C:\Users\shape_0102.dat
Now reading C:\Users\shape_0103.dat
Now reading C:\Users\shape_0104.dat
Now reading C:\Users\shape_0105.dat
Now reading C:\Users\shape_0106.dat
Now reading C:\Users\shape_0107.dat
........

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

채택된 답변

Stephen23
Stephen23 2020년 11월 4일
편집: Stephen23 2021년 4월 18일
Adapting from the examples in the NATSORTFILES documentation:
..
S = dir(fullfile(myFolder,'shape_0*.txt'));
S = natsortfiles(S); % alphanumeric sort by filename
for k = 1:numel(S)
baseFileName = S(k).name;
..
end
  댓글 수: 1
Tesla
Tesla 2020년 11월 4일
Now working! thank you very much, you saved me!

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 11월 4일

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by