フィルターのクリア

How do I get a script to wait until a figure is closed?

171 ビュー (過去 30 日間)
John Hackett
John Hackett 2018 年 3 月 10 日
コメント済み: Walter Roberson 2018 年 3 月 10 日
So basically I have a gui, with a button press. On button press it runs a script that has a startBackground command in it. But before the figure from the script can even pop up, I get an error stating that a session was closed while it was running. However, I want the script to run until the user closes the figure. Basically it is a live figure, showing live inputed data during a certain range.
How do I do this?
After I run the script I can extend the time the script is running by putting a pause command, but I want the script to continue for an indeterminate amount of time, basically until the user closes it.
  3 件のコメント
John Hackett
John Hackett 2018 年 3 月 10 日
Thanks, uiwait was exactly what I needed, no clue why google didn't return something like that.
Walter Roberson
Walter Roberson 2018 年 3 月 10 日
See also waitfor()

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

回答 (1 件)

Ahmet Cecen
Ahmet Cecen 2018 年 3 月 10 日
uiwait will probably halt the execution completely. I think you want the program to keep running until the figure is closed instead.
I am not entirely sure yet as I am not in front of a computer, but I believe you can do this instead:
f = imagesc; %Some Figure
while size(findobj(f))>0
'me' %some action
pause %some input
end
So if at any point the user closes the figure, your routine will break out of the while loop after the current iteration executes.
  2 件のコメント
per isakson
per isakson 2018 年 3 月 10 日
編集済み: per isakson 2018 年 3 月 10 日
Invoke this line and close the figure interactively
>> h = figure; uiwait(h); disp('figure closed')
Ahmet Cecen
Ahmet Cecen 2018 年 3 月 10 日
編集済み: Ahmet Cecen 2018 年 3 月 10 日
Ok can check things now. If I did this:
k = figure;
uiwait(k)
'me' %some action
pause %some input
'me' doesn't get printed until the figure is closed. My impression from above from reference to a "live" figure is that he wants to program to run and update the figure "as long as" the figure is open, like plotting the reading from a sensor while figure is present. Unless I am making a mistake somewhere uiwait is instead choking the execution, so the figure will not update.
Where as this:
k = figure; %Some Figure
while size(findobj(k))>0
'me' %some action
pause %some input
end
makes it so that while the figure is open, you can keep pressing stuff and "me" will keep printing, so the program is still running and the loop is iterating.
Will leave it to the poster to choose the snippet that he intended to ask for. Apparently he meant to choke the execution instead.

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

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by