How make MATLAB waitbar message indicate the filename being processed?

15 ビュー (過去 30 日間)
farzad
farzad 2020 年 4 月 4 日
編集済み: Walter Roberson 2020 年 4 月 5 日
Hi All
I have to process some files in a folder in a for loop.
as per examples in web , I wanted to try :
h = waitbar(0,'Please wait...');
for step = 1:1000
% computations take place here
waitbar(step/1000)
drawnow
end
close(h)
but this, has one problem. I want the window message change with the change in filename and say like : processing filename1. etc.
the other issue is : this progress bar flashes in each loop, and closes immediately till the next iteration. there is no control over that ?
what does drawnow do ?
  2 件のコメント
Rik
Rik 2020 年 4 月 4 日
Have you read the documentation pages for waitbar and drawnow?
farzad
farzad 2020 年 4 月 5 日
sorry, yes, but it was too complicated and I had never used it before

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

採用された回答

Walter Roberson
Walter Roberson 2020 年 4 月 4 日
persistent h
if isempty(h) || ~isvalid(h)
h = waitbar(0,'Please wait...');
end
for step = 1:1000
thisfilename = FileNames{step}; %adjust this line as needed
waitbar(step/1000, h, sprintf('Processing %s', thisfilename))
% computations take place here
drawnow
end
waitbar(1, h, 'Processing done. Proceeding with other computations')
This will update the waitbar message each iteration. It will also keep the waitbar alive between invocations of the code, such as if you have another loop around all of this.
  14 件のコメント
farzad
farzad 2020 年 4 月 5 日
problem solved. had to paste h = waitbar(0,'Please wait...'); also into the try loop
Walter Roberson
Walter Roberson 2020 年 4 月 5 日
編集済み: Walter Roberson 2020 年 4 月 5 日
No, the code
persistent h
if isempty(h) || ~isvalid(h)
h = waitbar(0,'Please wait...');
end
takes care of that. As I showed in
that code is within the section that is being invoked repeatedly.

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

その他の回答 (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