GUI plot listening to several components value chage

2 ビュー (過去 30 日間)
Huayan Wang
Huayan Wang 2018 年 2 月 7 日
コメント済み: Huayan Wang 2018 年 2 月 7 日
I have a pushbutton, radio button and checkbox to control one plot in GUI.
I would press the pushbutton to plot and then every time I do a value change to the radio button and checkbox, the plot will update accordingly.
The way I can think is to copy and paste the plot code into every component callback. But it is a pain to change the plot function. I think there must be an easy way to do so. Something like to make the component broadcast the value change and the plot function as a listener will update accordingly.
Anybody can give me a hint? Thanks in advance!
  2 件のコメント
Adam
Adam 2018 年 2 月 7 日
Your plot function should be factored out from the callback and simply take the inputs it needs to update the plot. This depends on what is being plotted. Ideally if it is e.g. a single line plot that updates you should plot it once, for the first time, then keep its handle, then future updates should just change the XData and YData (and any other properties that may need updating) of this line object.
Either way though you should just do something like this:
function plot( someArgs )
% do plotting update
function pushButtonCallback( ... )
% Get relevant arguments
plot( ... )
function checkboxCallback( ... )
% Get relevant arguments
plot( ... )
function radioButtonCallback( ... )
% Get relevant arguments
plot( ... )
Huayan Wang
Huayan Wang 2018 年 2 月 7 日
Thank you Adam!
That helps.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by