Matlab - 使用计时器绘制相同的指南轴

时间:2015-04-07 19:24:07

标签: matlab plot

在我的gui中我有一个斧头(f1)并且我试图绘制2个以某些频率改变颜色的矩形,它运行良好但是在定时器的第一次迭代之后它打开一个新的数字并进行colores的迭代,我不知道为什么它会打开一个新的数字。 enter image description here

这是启动过程的按钮代码:

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

我也尝试axes(handles.f1);在开始但是它做了相同的

1 个答案:

答案 0 :(得分:0)

哦我解决了它将''属性添加到我的身材中,不知道为什么在我之前的代码中第一次工作而其余的不行,但我认为这是一个很好的解决方案:

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

希望它帮助有同样问题的人