How to delete line in GUI axes with multiple lines?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mischa Klene
el 15 de Nov. de 2018
Comentada: Mischa Klene
el 15 de Nov. de 2018
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
0 comentarios
Respuesta aceptada
Adam Danz
el 15 de Nov. de 2018
Editada: Adam Danz
el 15 de Nov. de 2018
The reason why the code doesn't remember the handle to l_1 is because once the callback function is finished, the variables no longer exist in memory.
One solution is to make l_1 a persistant variable. At the top of the callback function, include the following line.
persistent l_1
A second solution is to tag the object and then search for the tag.
% plot with tag
l_1 = plot (handles.test,data_left_col1, 'tag', 'MyUniqueTagName');
% search for tag and delete
l_1 = findobj('tag', 'MyUniqueTagName');
delete(l_1) %this will delete ALL objects with this tag
Más respuestas (1)
Nick
el 15 de Nov. de 2018
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 comentario
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!