Clear a line drawn in plot.
107 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello I would like to clear a line that I draw in my graph but I want it to be clean only when I run my function.
When I press button in Matlab GUI I want to draw a line but when I pressed it second time I want to clear that line and draw other. How to simply do this.
0 commentaires
Réponse acceptée
David Sanchez
le 16 Sep 2013
Implement this in the pushbutton:
children = get(gca, 'children');
delete(children(1));
The first line grabs the last additions to the figure, the second line deletes from the plot the last element added to the figure.
3 commentaires
Jan
le 16 Sep 2013
@Joansz: We cannot guess what you are doing exactly. Because the question is vague only, we can suggest some methods, but not a running piece of code. When you show us the relevant part of your code, more exactly answers are possible.
Plus de réponses (1)
Simon
le 16 Sep 2013
Hi!
Each time you plot something with the "h=plot" command, it gives you as return value the handle "h" of that plot. Then you may use
delete(h)
You just need to remember this handle (store it somewhere ...)
4 commentaires
Simon
le 17 Sep 2013
So, in your code above you have everything you need. Storing a variable for future use is done using "guidata". See http://www.mathworks.com/help/matlab/ref/guidata.html?searchHighlight=guidata
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!