Matlab-使用计时器在导轨的同一轴上绘图

Matlab-使用计时器在导轨的同一轴上绘图,matlab,plot,Matlab,Plot,在我的gui中,我有一个斧头(f1),我试图画两个矩形,以一定频率改变它的颜色,它工作得很好,但在计时器的第一次迭代后,它打开了一个新图形,并进行了颜色的迭代,我不知道为什么它会打开一个新图形。 这是启动流程的“我的”按钮的代码: function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to b

在我的gui中,我有一个斧头(f1),我试图画两个矩形,以一定频率改变它的颜色,它工作得很好,但在计时器的第一次迭代后,它打开了一个新图形,并进行了颜色的迭代,我不知道为什么它会打开一个新图形。

这是启动流程的“我的”按钮的代码:

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%%t1 = timer('ExecutionMode','fixedRate','TasksToExecute',50,'TimerFcn',@f1,'Period',.05);
%%t2 = timer('ExecutionMode','fixedRate','TasksToExecute',10,'TimerFcn',@freq2,'Period',.5);
h=findobj('Type','axes','Tag','f1');
axes(h);
i1=1;
i2=1;
t1 = timer('ExecutionMode','fixedRate','TasksToExecute',50,'TimerFcn',@freq1,'Period',.05);
t2 = timer('ExecutionMode','fixedRate','TasksToExecute',10,'TimerFcn',@freq2,'Period',.5);


colores1=['b';'w'];
colores2=['r';'g'];

start(t1);
start(t2);
%%rectangle('Position',[0,0,.5,.5],'Facecolor','r');
disp('h');
function freq1(obj,event)
% Scale and display image
%%disp('hola');
i1=mod((i1+1),2);
axes(h);
rectangle('Position',[0,0,1,1],'Facecolor',colores1(i1+1))
end
function freq2(obj,event)
% Scale and display image
%%disp('hola');
i2=mod((i2+1),2);
axes(h);
rectangle('Position',[1,1,1,1],'Facecolor',colores2(i2+1))
end
end

我还尝试
轴(handles.f1)
在Begging上,但它做了同样的事情,哦,我解决了它,在我的图中添加了“Parent”属性,我不确定为什么在我以前的代码中第一次工作,其余的没有,但我认为这是一个很好的解决方案:

rectangle('Position',[0,0,1,1],'Facecolor',colores1(i1+1),'Parent',h);
其中h是我的handler.axe,我的代码以以下方式结束:

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%%t1 = timer('ExecutionMode','fixedRate','TasksToExecute',50,'TimerFcn',@f1,'Period',.05);
%%t2 = timer('ExecutionMode','fixedRate','TasksToExecute',10,'TimerFcn',@freq2,'Period',.5);
%%h=findobj('Type','axes','Tag','f1');
axes(handles.f1);
i1=1;
i2=1;
t1 = timer('ExecutionMode','fixedRate','TasksToExecute',50,'TimerFcn',{@freq1,handles.f1},'Period',.05);
t2 = timer('ExecutionMode','fixedRate','TasksToExecute',5,'TimerFcn',{@freq2,handles.f1},'Period',.5);


colores1=['b';'w'];
colores2=['r';'g'];

start(t1);
start(t2);
%%rectangle('Position',[0,0,.5,.5],'Facecolor','r');
disp('h');
function freq1(obj,event,h)
% Scale and display image
%%disp('hola');
i1=mod((i1+1),2);
axes(h);
rectangle('Position',[0,0,1,1],'Facecolor',colores1(i1+1),'Parent',h);
end
function freq2(obj,event,h)
% Scale and display image
%%disp('hola');
i2=mod((i2+1),2);
axes(h);
rectangle('Position',[1,1,1,1],'Facecolor',colores2(i2+1),'Parent',h);
end
end
希望它能帮助有同样问题的人