Is it possible to use exist function in a loop?

for i=1:5
filename_1 = ['E:\Abhi\file_',num2str(i)];
save (filename_1)
end
for j=1:9
filename_1 = ['E:\Abhi\file_',num2str(j)];
exist('filename_1','file') % not sure how to write this exactly
end
here I expect to get answer 2 for file_1 to file_5 and for rest others as 0.
Thanks.

 Akzeptierte Antwort

Matt Fig
Matt Fig am 5 Dez. 2012

0 Stimmen

Did you try it? The help for EXIST indicates you can use it as you are doing.

3 Kommentare

Yes. I tried following also but not working
exist('filename_1.mat','file')
exist([filename_1,'.mat'],'file')
Abhijeet
Abhijeet am 5 Dez. 2012
Thank you very much!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by