when i have two plots on same figure, how can i clear only one plot ??

3 views (last 30 days)
I have two plots.
Out of which one is permanent data, which is not varying with time.
Second one is varying frequently with time.
I want to clear only the second one every time. What is the procedure to do it.

Answers (2)

Arthur
Arthur on 25 Nov 2012
Are there 2 axes, or 2 lines in one axes? If you have two axes: uou need the handles of the second axes to clear it with cla.
cla(axeshandle)
With 2 lines on the same axes, you can use the handle of the line that you plot:
linehandle = plot(yourdata);
%and to delete it:
delete(linehandle)

Azzi Abdelmalek
Azzi Abdelmalek on 25 Nov 2012
%Look at this example
t=0:0.1:10;
y1=sin(t)
y2=cos(t)*10
% plot your first data
plot(t,y1,'r')
ax1=gca
pos=double(get(ax1,'position'));
%plot your second data
ax2=axes('position',pos,'color','none')
plot(t,y2,'g','parent',ax2)
set(ax2,'visible','off')
ax3=axes('position',pos,'color','none','xtick',[],'Yaxislocation','right','ylim',[min(y2) max(y2)])
%change your second plot
y2=t.^2;
cla(ax2);
set(ax3,'visible','off')
plot(t,y2,'g','parent',ax2)
set(ax2,'visible','off')
ax3=axes('position',pos,'color','none','xtick',[],'Yaxislocation','right','ylim',[min(y2) max(y2)])

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!