Reputation: 760
I have some files to process , but i have missing files in middle i am using
for i=1:file;
fid = fopen(['Raw',num2str(i),'.txt']);
D = textscan(fid1,'%*f %f%*f%*f%*f%f%f%[^\n]','delimiter',';', 'headerlines',50,'CollectOutput', 1);
fclose(fid);
Now the rest of program works well when i have files in order
i.e, 100,200 any number of files in my folder in order as Raw1.txt, Raw2.txt, Raw3.txt, ....
I get into trouble as soon as there are missing files like Raw1.txt, Raw4.txt, Raw5.txt
How do i iterate my text scan so it can ignore the file numbering?
Thanks
Edit :
By missing files i mostly mean numbers after 'Raw'
My files get generated as Raw1, Raw2, Raw3............ Raw400.txt
When all the files are in order and present i have no problem.
when i have some missing or jumps like for example Raw1 . Raw2.......... Raw10, Raw15, Raw16 I have trouble as there is jump from Raw10.txt to Raw15.txt I have same problem if my files start at anything other than Raw1.txt
Upvotes: 1
Views: 222
Reputation: 26069
look for exist
in matlab documentation. Something like this should work:
for i=1:file;
if exist(['Raw',num2str(i),'.txt'], 'file')
% File exists!
fid = fopen(['Raw',num2str(i),'.txt']);
D = textscan(fid1,'%*f %f%*f%*f%*f%f%f%[^\n]','delimiter',';', 'headerlines',50,'CollectOutput', 1);
fclose(fid);
end
end
Note that exist(Name, 'file')
checks for the file's directory too, so either give the full file name (i.e. with path), or try something like if exist(Name, 'file') == 2
Upvotes: 1