How to delete line in GUI axes with multiple lines?
Show older comments
I have got a GUI with checkboxes and an axes. The checkboxes load in data which is then plotted into the axes. When the checkbox is untagged, I want the line to be deleted. In the code below, the l_1 is plotted and I tried to delete l_1 after, but it does not know what l_1 is. How can I delete line l_1 from the axes?
Value_left_col1 = get(hObject,'Value');
if Value_left_col1 == 1
data_left = xlsread('Axes_left_data');
data_left_col1 = data_left(:,1);
l_1 = plot (handles.test,data_left_col1);
else
delete(l_1)
end
Accepted Answer
More Answers (1)
Nick
on 15 Nov 2018
1 vote
I am assuming this is inside a function, once the function is completed all variables that are not part of the output (or global) will be lost, so if your function output has handles or have some global struct holding your data assign l_1 to that variable and then you will be able to delete it.
It looks a bit unnecessary to delete the line plot completely if no new data is loaded, you could just assign the 'Visible' property of the plot to 'off' or 'on' depending on the checkbox value.
A less clean way is to check for the lineplot inside the children of the axes object where you are displaying it in and deleting this handle. Depending on how many children this axes object has this can be a simple but not very clean solution.
1 Comment
Mischa Klene
on 15 Nov 2018
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!