Is it possible to use exist function in a loop?

2 ビュー (過去 30 日間)
Abhijeet
Abhijeet 2012 年 12 月 5 日
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.

採用された回答

Matt Fig
Matt Fig 2012 年 12 月 5 日
Did you try it? The help for EXIST indicates you can use it as you are doing.
  3 件のコメント
Matt Fig
Matt Fig 2012 年 12 月 5 日
exist([filename_1,'.mat'],'file')
Abhijeet
Abhijeet 2012 年 12 月 5 日
Thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by