Clearing plot in GUI axes
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have 10 variables with data which I want to plot against time. I generated checkboxes with the corresponding name of the variable and axis in a figure. when the user checks a checkbox, the data corresponding to the variable it to be plotted with time series. I am using plot command in the checkbox callback function and was able to plot when it was checked. But when the checkbox is unchecked the plot still remains in the figure. I used cla command to clear the plot. The problem is when multiple checkboxes are selected and if one checkbox is unchecked all the plots are being cleared. I need to clear the plot only for which the checkbox is unchecked. kindly help... Thanks in advance
3 commentaires
Image Analyst
le 30 Mai 2022
Modifié(e) : Image Analyst
le 30 Mai 2022
@Reza Lashani in the callback for each individual checkbox, clear the one axes that corresponds to that checkbox. For example in the callback for chkClearAxes1, have
if handles.chkClearAxes1.Value
cla(handles.axes1, 'reset');
end
Do it similarly for all the other checkboxes.
Reza Lashani
le 30 Mai 2022
yes but this command clears all plotted diagrams in axes. there is already other diagrams plotted in the same axes, I just want to delete one of them after the checkbox is unchecked and plot it when it is checked.
I have tried such code: (The checkbox is unchecked at the begining)
function CheckBoxDiagram_Callback(hObject, eventdata, handles)
x = 0: 0.02: 1;
y = sin(x);
if get(handles.CheckBoxDiagram, 'value')
Diagram = plot(handles.axes1, x, y, 'r--');
else
delete(Diagram)
end
But I get this error:
Undefined function or variable "Diagram".
Réponses (1)
Brendan Hamm
le 27 Août 2015
You need only get the plot objects (or handles prior to 2014b) to delete that individual plot.
f = figure;
a = axes('Parent',f);
x = linspace(0,2*pi);
hold on
for k = 1:3
p(k) = plot(a,x,sin(x/k));
end
We can now just delete the individual plot object:
delete(p(1))
It seems you may have a check box for each possible plot, so you may want to just initialize a vector of plot objects:
p = gobjects(numOfPlots,1);
so that you can always assign the plot from the first check box to p(1) and from the nth checkbox to p(n).
4 commentaires
Brendan Hamm
le 21 Sep 2015
Presumably you have replaced the line:
p=gobjects(length(txt),1);
with
p = zeros(length(txt),1);
as you mention you are using 2007b.
In this case if you do not assign to one of the elements of p, the value of this element remains 0. When you call:
delete(0)
you will get an error as 0 is used for the root (that is information from your graphics card pertaining to your display). You could place another conditional to ensure that p(index) ~= 0 before deleting in this case.
Voir également
Catégories
En savoir plus sur Graphics Object Programming dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!