Radio button and format of plot axis in app designer and its corresponding plot

7 ビュー (過去 30 日間)
In order to plot the death cases on either both or right Y-axis I used following functions:
yyaxis(app.UIAxes,'left')
yyaxis(app.UIAxes,'right')
The problem now is, how to undo the settings when switching the radio buttons. These functions seem to freeze the display and the deaths curve won't fade away when I switch to show only covid cases, for instance. My default setting for both will not be replaced when I switch to only cases or only deaths (left radio button below):
This is the code I wrote to select the difference cases(plot function):
function plotData(app) %default values missing
%plot data depending on selection from radion buttons
cla reset
if app.ShowCases
yyaxis(app.UIAxes,'left')
app.UIAxes.YLabel.String='Cases';
plot(app.UIAxes,app.TimeLine,app.Positives);
end
if app.ShowDeaths
yyaxis(app.UIAxes,'right')
app.UIAxes.YLabel.String='Deaths';
plot(app.UIAxes,app.TimeLine,app.Deaths);
end
if app.ShowBoth
yyaxis(app.UIAxes,'left')
app.UIAxes.YLabel.String='Cases';
plot(app.UIAxes,app.TimeLine,app.Positives);
yyaxis(app.UIAxes,'right')
app.UIAxes.YLabel.String='Deaths';
plot(app.UIAxes,app.TimeLine,app.Deaths);
end
end
end
And the code I wrote for the event triggering selection from the radio button:
app.ShowCases = app.CasesButton.Value;
app.ShowDeaths = app.DeathsButton.Value;
app.ShowBoth = app.BothButton.Value;
app.plotData;
Without the functions yyaxis(app.UIAxes,'left'/'right') the switch of the plot wil work, but I cannot use the right Y axis though. I have problems to understand the information in the MATLAB documentation and it is not intuitive to found valuable hints by introducing some key words. Thanks in advance to anyone who has a hint for this.

採用された回答

Benjamin Kraus
Benjamin Kraus 2021 年 1 月 5 日
編集済み: Benjamin Kraus 2021 年 1 月 5 日
I think the problem you are having is that you are not passing your axes handle into the cla function.
cla(app.UIAxes, 'reset');
As currently written, cla is operating on the "current axes", which is probably not the one in your app. Have you noticed that when that function runs a separate figure window pops open?
Because you are not resetting the axes, when you call plot it is only removing the children from the one side of the yyaxis that is active, rather than resetting the entire axes.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by