How to switch cases if certain file is not found in the mentioned directory?

1 回表示 (過去 30 日間)
Mr. 206
Mr. 206 2019 年 2 月 25 日
編集済み: Mr. 206 2019 年 2 月 25 日
My script run three different conditions at a time. For this it takes three files as input from certain directory. But sometimes there can be one input files or two. So how can I set switch command that will check the directory for first condition and if the files are not found it will move to new conditions.
Here is my dummy code structure,
Condition 01
Experiment_folder = '/home/ali';
Exp_uncertainty = dir(fullfile(Experiment_folder,'*experimental_uncertainty_IDT.txt'));
(If not found move to condition 02)
.
.
commands
.
.
end
Condition 02
Experiment_folder = '/home/ali';
Exp_uncertainty = dir(fullfile(Experiment_folder,'*experimental_uncertainty_LFS.txt'));
(If not found move to condition 03)
.
.
commands
.
.
end
Condition 03
Experiment_folder = '/home/ali';
Exp_uncertainty = dir(fullfile(Experiment_folder,'*experimental_uncertainty_JSR.txt'));
.
.
commands
.
.
end

採用された回答

Walter Roberson
Walter Roberson 2019 年 2 月 25 日
dir() will return an empty result if nothing matches; you can test with isempty()
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 2 月 25 日
if ~isempty(Exp_uncertainty)
....
end
Mr. 206
Mr. 206 2019 年 2 月 25 日
編集済み: Mr. 206 2019 年 2 月 25 日
Thanks, It works.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by