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 CenterFile Exchange에서 Networks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by