2015-04-07 4 views
0

В моем gui у меня есть топор (f1) и Im, пытающийся нарисовать 2 прямоугольника, которые меняют цвет с некоторой частотой, хорошо работает, но после первой итерации таймеров он открывает новую фигуру и выполняет итерацию цветов, я не знаю, почему она открывает новую фигуру. enter image description hereMatlab - Построение в тех же осях гида с таймерами

это код моей кнопки, чтобы начать процесс:

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); на самом начало, но он сделал то же самое

ответ

0

О, я решил его добавление "Родитель 'собственность моей фигуре, не знаю, почему в моем предыдущем коде работают в первый раз, а остальные нет, но я думаю, что это хорошее решение:

rectangle('Position',[0,0,1,1],'Facecolor',colores1(i1+1),'Parent',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 

Надеется, что это помогает кто-то с той же проблемой

Смежные вопросы