I want to put multiple plots on a graph but be able to turn on and off the visibility for a few plots

1 回表示 (過去 30 日間)
I have a graph with a few different plots on (circles,lines,points). I want to be able to have those plots hidden or shown-depending on a switch. Right now i have a switch
function switchValueChanged(app,event)
value = app.Switch.Value;
if strcnp(value,'On')
y=x+1;
plot(app.UIaxis,x,y);
end
end

回答 (1 件)

Kevin Holly
Kevin Holly 2022 年 12 月 2 日
Create a property variable
properties
p
end
Define that property value (do so in startup function or in callback function - whichever is applicable to your application)
y=x+1;
app.p = plot(app.UIaxis,x,y);
Toggle visibility of the plot
function switchValueChanged(app,event)
if strcnp(app.Switch.Value,'On')
app.p.Visible = "on"
else
app.p.Visible = "off"
end
end

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by