How to halt program until file input?

Hi, I am making an image processing program and want to know if there is a way to halt the program and make it wait for a image to be created before it is read. To put it into context,
imagefiles = dir('*.jpg');
nfiles = length(imagefiles);
for a = 1:200
filename = ['image-' num2str(a,'%02d') '.jpg'];
image = imread(filename);
I understand pause(n) might work but because the inputted images take different times to be snapped, I would like to make it dependent on when the file appears.
Any suggestions would be great!

 採用された回答

Joseph Cheng
Joseph Cheng 2014 年 6 月 27 日

1 投票

You could put in a while loop checking whether the file exist().
count = 0;
while exist(filename)==0
pause(1)
count = count+1;
if count ==10000
disp('no file was generated in allowed time');
break
end
I also put in a simple time out as well. I suggest you put in a

1 件のコメント

Michael
Michael 2014 年 6 月 27 日
Didn't know I could use the function "exist" with the "filename" variable. Thanks for the help!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

質問済み:

2014 年 6 月 27 日

コメント済み:

2014 年 6 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by