How do I print the filenames with for and assign them to another variable?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have 10 .mat files. "data1.mat", "data2.mat", "data2.mat" ... I want to store these files in an array named "file" by throwing them into a for loop. I wrote a code like this for him.
for i = 1:10
file = sprintf ('data% d.mat', i);
if exist (file) == 2
end
end
however, it writes the file "data10.mat" to the file. I want files starting from 1 to 10 to be uploaded to the "file" file. How can I do it?
답변 (1개)
Walter Roberson
2021년 4월 22일
for i = 1:10
file = sprintf ('data%d.mat', i)
if exist (file) == 2
fprintf('file "%s" exists with type 2\n', file);
else
fprintf('file "%s" does not exist with type 2\n', file)
end
end
(It happens that data1.mat exists in one of the Sym Biology examples.)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!