matlab - Clear all graphical object of a certain type -


i created gui program matlab, menu bar , tabs, each containing plot, text box, etc. problem when select tab menu bar , plot something, axes objects former plots don't disappear.

i tried use cla reset unsuccessfully. clf worked, menu bar disappeared well.

here code:

function fel1_callback(hobject, eventdata, handles) %% plot sin(x)         cla reset     clc     clear      d = inputdlg('n:','ertekadas',1);     n = str2double(d);      x=linspace(-3*pi,3*pi,1000);     y=sin(x);     plot(x,y,'k','linewidth',4)     sz='ymcrgbkymcrgbkymcrgbkymcrgbk';     hold on     title('sin(x) taylor sora')     %n = str2num(n);     f=zeros(size(x));     i=1:n         t=(-1)^(i-1)*x.^(2*i-1)/factorial(2*i-1);         f=f+t;         plot(x,f,sz(i),'linewidth',2)         axis([-10 10 -10 10])         pause(0.1)         hold on         n=n+1;     end  function fel7_callback(hobject, eventdata, handles) %%sum 1/n^2     clear     clc     cla reset      title('suma 1/n^2','fontsize',20)     d = inputdlg('epszilon:','ertek',1);     epsz = str2double(d);     n=1;     x=0;     while 1/n^2>epsz         x=x+sum(1/n^2);         n=n+1;     end      = uicontrol('style','text','units','pixels',...         'position',[550 550 120 40],'fontsize',20,'string','epsz =');     b = uicontrol('style','text','units','pixels',...         'position',[670 550 120 40],'fontsize',20);     set(b,'string',epsz)     c = uicontrol('style','text','units','pixels', ...         'position',[550 400 120 40],'fontsize',20,'string','osszeg =');     d = uicontrol('style','text','units','pixels',...         'position',[670 400 120 40],'fontsize',20);     set(d,'string',x) 

i use 1 main gui figure. menu bar contains lot of plots , calculations, not these two.

the problem hold on prevents being erased , keeps adding plot. in code turn hold off. if want keep using hold command, code needs this:

function fel1_callback(hobject, eventdata, handles) %% plot sin(x)      d = inputdlg('n:','ertekadas',1); n = str2double(d);  x=linspace(-3*pi,3*pi,1000); y=sin(x); hold off % next plot command should clear old plot , create new one** plot(x,y,'k','linewidth',4) sz='ymcrgbkymcrgbkymcrgbkymcrgbk'; hold on title('sin(x) taylor sora') %n = str2num(n); f=zeros(size(x)); i=1:n     t=(-1)^(i-1)*x.^(2*i-1)/factorial(2*i-1);     f=f+t;     plot(x,f,sz(i),'linewidth',2)     axis([-10 10 -10 10])     pause(0.1)     %hold on  %not necessary, turned on before loop     n=n+1; end hold off  % return figure normal (default) "hold off" state 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -