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

3 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Benjamin Kraus
Benjamin Kraus le 5 Jan 2021
Modifié(e) : Benjamin Kraus le 5 Jan 2021
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.

Plus de réponses (0)

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by