Remove a line from a plot in UIAxes App Designer
Show older comments
Hello Everyone,
I would like to add or remove a line from a UIAxes, using the Switch Button.
When the switch button is on, everything is working and the curve is plotted. But when I switch to off, the line still remains, and it is not removed from the graph.
In the UIAxes toolbar, I have set the Multiple Plots settings in this way:
NextPlot: add; SortMethod: childorder
This is the code I used, but it is not working:
Thank You!!
function SperimentaleSwitchValueChanged(app, event)
value = app.SperimentaleSwitch.Value;
if strcmp(value, 'On')
exp = importdata('...\Sperimentale.txt');
exp_force = exp(:,2);
exp_displ = exp(:,1);
h1 = plot (app.UIAxes, exp_displ, exp_force/1000)
end
if strcmp(value, 'Off')
delete(h1)
end
end
1 Comment
Prajwol Tamrakar
on 9 Aug 2023
See app.UIAxes.Children!! Each plot you created will be included here. The latest plot will be included on top. If you have four line plots, you can delete the first one by
delete(app.UIAxes.Children(4))
Similary, to delete the latest plot, use
delete(app.UIAxes.Children(1))
Hope this is helpful!!
Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!