Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Is it possible to use exist function in a loop?

Asked by Abhijeet on 5 Dec 2012
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.

0 Comments

Abhijeet

Products

No products are associated with this question.

1 Answer

Answer by Matt Fig on 5 Dec 2012
Accepted answer

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

3 Comments

Abhijeet on 5 Dec 2012

Yes. I tried following also but not working

exist('filename_1.mat','file')
Matt Fig on 5 Dec 2012
exist([filename_1,'.mat'],'file')
Abhijeet on 5 Dec 2012

Thank you very much!

Matt Fig

Contact us