簡體   English   中英

Matlab-在帶有計時器的引導軸上進行繪圖

[英]Matlab - Plotting in the same axes of guide with timers

在我的圖形用戶界面中,我有一個斧頭(f1),我試圖繪制2個矩形,這些矩形會以一定的頻率更改其顏色,效果很好,但是在計時器的第一次迭代之后,它打開了一個新圖形並進行了顏色迭代,我沒有知道為什么要開一個新的形象。 在此處輸入圖片說明

這是我啟動該過程的按鈕的代碼:

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); 在開始時,但它做了同樣的事情

哦,我解決了這個問題,在我的圖形上添加了“ 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

希望它可以幫助遇到同樣問題的人

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM