フィルターのクリア

How to insert a variable in 'exist' command in matlab?

2 ビュー (過去 30 日間)
Raguram N
Raguram N 2017 年 1 月 18 日
コメント済み: Steven Lord 2019 年 10 月 29 日
Hi all! I need to check the existence of a set of files with names as mentioned bellow.
data-0.0100-value-0.1000.dat
data-0.0200-value-0.2000.dat
data-0.0300-value-0.3000.dat
data-0.0400-value-0.4000.dat
data-0.0500-value-0.5000.dat
.
.
.
I know I can use 'exist' command to check the existence. But, I try to check using a for loop. In that case, I didn't know how to insert a variable in 'exist' command. I tried the following command:
c= 0.0100;
rr = 0.1000;
if exist('data-%4.4f-value-%4.4f.dat','file',c,rr) == 2
ddd=0;
end
I am getting error "Error using exist;Too many input arguments."
So how can I insert a variables in exist command? thanks in advance.
regards, raman

採用された回答

Honglei Chen
Honglei Chen 2017 年 1 月 18 日
You can use sprintf
if exist(sprintf('data-%4.4f-value-%4.4f.dat',c,rr),'file') == 2
HTH
  2 件のコメント
Wael Wanis
Wael Wanis 2019 年 10 月 28 日
what does 'file' stand for?
i understand c & rr are the two variables inside the sprintf but what is file?
Thank you in advance.
Steven Lord
Steven Lord 2019 年 10 月 29 日
It's one of the allowed values for the searchType input argument to the exist function.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by