Skip data files while reading input and writing output in matlab code

I use matlab code to read several files and write output in the following way:
n=202;
for idx = 0:n
infilename = sprintf('pt%d.txt',idx);
outname = sprintf('out%d.txt',idx);
Now if some arbitrary data files are missing e.g. pt20.txt, pt50.txt ,etc then the code is terminated. I would like to modify the code in a way that if some data files are not found then the code would skip them and proceed to reading/writing the next available data file.
Thank you.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 6월 17일
편집: Azzi Abdelmalek 2015년 6월 17일
infilename = sprintf('pt%d.txt',idx);
if exist(infilename)
%do
end

댓글 수: 2

Thank you for your reply. But I guess, it would be
if exist
not if exit? Then if I do so, then the code is terminated once it encounters the missing data file. So, if for example, the 8th data file is missing then it writes outputs before encountering the missing data file and them terminates.
yes, it was just a typo

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

카테고리

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

태그

질문:

2015년 6월 17일

편집:

2015년 6월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by