Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Clearing axes

Subject: Clearing axes

From: C?sar Ghali

Date: 11 Jan, 2009 20:08:02

Message: 1 of 6

Dear friends,

I am using an axes control on a GUI. I run a simulation that draws some curves on the axes control, then when I run the simulation again I want to clear the axes (delete the old curves when the simulation starts).

Any ideas, please. Thanks in advance for your help.


Cesar Ghali

Subject: Clearing axes

From: Matt Fig

Date: 11 Jan, 2009 20:33:01

Message: 2 of 6

>> plot(1:10)
>> cla

Subject: Clearing axes

From: Image Analyst

Date: 11 Jan, 2009 21:13:02

Message: 3 of 6

Here's a function that will remove just the lines, and leave the axes limits, and other stuff untouched.

%=================================================
function ClearLinesFromAxes(handles)
axesHandlesToChildObjects = findobj(gca, 'Type', 'line');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
return; % from ClearLinesFromAxes

Subject: Clearing axes

From: Matt Fig

Date: 11 Jan, 2009 22:28:02

Message: 4 of 6

"Image Analyst" <imageanalyst@mailinator.com> wrote in message <gkdncu$c7l$1@fred.mathworks.com>...
> Here's a function that will remove just the lines, and leave the axes limits, and other stuff untouched.
>
> %=================================================
> function ClearLinesFromAxes(handles)
> axesHandlesToChildObjects = findobj(gca, 'Type', 'line');
> if ~isempty(axesHandlesToChildObjects)
> delete(axesHandlesToChildObjects);
> end
> return; % from ClearLinesFromAxes


Must be a version/platform thing. 2007a, win vista 32bit
The above function behaves exactly like cla for me. This does it though:

function ClearLinesFromAxes(ax)
str = {'xlim','ylim','xtick','ytick'}; % Could add other props if desired.
prop = get(ax,str);
delete(get(ax,'child')); % Will delete ALL axes children.
set(ax,str,prop);




The above was tested with:

ax = axes;
x = 1:10;
plot(x)
hold on
plot(x.^2)
pause(2)
ClearLinesFromAxes(ax)

Subject: Clearing axes

From: Image Analyst

Date: 12 Jan, 2009 01:56:02

Message: 5 of 6

Well Matt you're right. At least now when I try it, but I'm pretty sure I tried it before and it didn't change xlim or ylim but now it's changing them both to [0 1]. What can I say?

Subject: Clearing axes

From: C?sar Ghali

Date: 12 Jan, 2009 13:07:02

Message: 6 of 6

Thanks guys, I used

cls(ax, 'reset');

because I want to reset the axes control to its default state and it works.

Thanks



Cesar Ghali

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us