Matlab App Designer: Update plot during loop in a function

The function I use is the callback function of a button. My issue is that when I execute a loop in the callback function, the plots in the UI Figure don´t update during the loop, but only show the last state after the loop is finished. I´d like to see the changing plot during the while loop in the UI Figure. Is this even possible, or do I have to add other functions, etc.?

 採用された回答

Allen
Allen 2019 年 12 月 20 日

1 投票

Assuming that your plot function is part of the while loop and you have the hold off, then you might try using pause and/or drawnow.
while condition
...
plot( ... )
drawnow(axes_handle)
pause(0.5)
...
end

4 件のコメント

Nikolas Dehler
Nikolas Dehler 2020 年 1 月 7 日
Thanks, it worked immediatly the way I wanted it.
Evgin Ün
Evgin Ün 2020 年 3 月 24 日
Hi Nikolas,
i have the same problem. I'd like to see the changing plot during the loop, too. Can you post your code for the plot here. That would be very cool.
Thank you.
Nikolas Dehler
Nikolas Dehler 2020 年 3 月 25 日
編集済み: Nikolas Dehler 2020 年 3 月 25 日
% that´s not the comlete code. I hope it´s sufficient for you.
function startupFcn(app) % I think you only need this if you want to see something in your plot before pushing the button.
scatter(app.UIAxes2,app.x,app.y); % x and y are vectors
hold(app.UIAxes2,'on');
end
function startButtonPushed(app, event)
while app.i < app.number
% calculation of app.cd
plot(app.UIAxes,app.i,app.cd);
hold(app.UIAxes,'on');
% you could plot anything this way. With the drawnow function, it will update continuously.
app.i = app.i+1;
hold(app.UIAxes2,'off');
scatter(app.UIAxes2,app.x,app.y);
hold(app.UIAxes2,'on');
drawnow
end
end
Evgin Ün
Evgin Ün 2020 年 4 月 6 日
Thank you very much Nikolas!

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

2019 年 12 月 20 日

コメント済み:

2020 年 4 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by