Is it possible to use exist function in a loop?

2 visualizaciones (últimos 30 días)
Abhijeet
Abhijeet el 5 de Dic. de 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.

Respuesta aceptada

Matt Fig
Matt Fig el 5 de Dic. de 2012
Did you try it? The help for EXIST indicates you can use it as you are doing.
  3 comentarios
Matt Fig
Matt Fig el 5 de Dic. de 2012
exist([filename_1,'.mat'],'file')
Abhijeet
Abhijeet el 5 de Dic. de 2012
Thank you very much!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by