Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MATLAB, how does one clear the last thing plotted to a figure?

In MATLAB, I plot many different vectors to a figure. Now, what I would like to do is simply undo the last vector that I plotted to that figure, without clearing everything else. How can this be accomplished? Can it be accomplished?

Thanks

Edit:

figure(1); clf(1);
N = 100;
x = randn(1,N);
y = randn(1,N);
z = sin(1:N);
plot(x); hold on;
plot(y,'r');
plot(z,'k'); 

Now here, I would like to remove the plot z, which was the last plot I made.

like image 433
Spacey Avatar asked Jul 10 '12 18:07

Spacey


People also ask

How do you clear data from a figure in MATLAB?

To clear the contents of a figure, you can alternatively use Clear Figure from the figure window's Edit menu. Using Clear Figure deletes all children of the figure that have visible handles.

Which command is used to clear the plot select one close figure () CLC () Clear () CLF ()?

clf() clears the entire current figure with all its axes, but leaves the window opened, such that it may be reused for other plots. plt. close() closes a window, which will be the current window, if not specified otherwise.

How do you clear an AXE in MATLAB?

Clear Axes and Reset All Axes PropertiesCreate a line plot and set the axis limits. Clear the line plot from the axes and reset all the axes properties to their default values. cla reset resets all properties of the current axes, except for the Position and Units properties.


2 Answers

If you know before plotting that you want to remove it again later, you can save the handle returned by plot and delete it afterwards.

figure;
h1 = plot([0 1 2], [3 4 5]);
delete(h1);
like image 94
groovingandi Avatar answered Oct 12 '22 01:10

groovingandi


Try

items = get(gca, 'Children');
delete(items(end));

(or maybe delete(items(1)))

like image 43
Ben Voigt Avatar answered Oct 12 '22 01:10

Ben Voigt