Use a variable with a file extenstion to load files

조회 수: 1 (최근 30일)
David
David 2014년 8월 14일
댓글: David 2014년 8월 14일
Hi,
I Have 51 files in their own directory all of .out extention created by a seperate program, all numbered 0 to 50.
ie
0.out
1.out
2.out
and so on til 50.out.
I need to load each file 1 by one to do calculations upon them within a for loop. How would I do this using the count variable to load the file, if the directory is set beforehand?
i.e.
%set directiory
cd(......)
%for loop
For count = 0:50,
data = count.out *<-----this line*
.....
Many thanks!

채택된 답변

Chad Greene
Chad Greene 2014년 8월 14일
You can use sprintf or num2str. num2str is easier to use, but sprintf gives many more options including leading zeros.
  댓글 수: 2
Chad Greene
Chad Greene 2014년 8월 14일
data = load([num2str(count),'.out']);
David
David 2014년 8월 14일
thanks:)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by