How to set timer

조회 수: 7 (최근 30일)
Sharmen
Sharmen 2011년 5월 16일
Hi, how to set timer for a Pushbutton in GUI. Lets say if a pushbutton is pressed and after 5 second it should do "set(pushbutton1.text1,'string','part1')" and let say after 10 seconds it should do " set(pushbutton1.text3,'string','part2')". How do i do this step?
thanks sharmen

답변 (2개)

Andy
Andy 2011년 5월 16일
You might want to take a look at Matt Fig's http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples. Specifically, "19.How can I use a timer in a GUI? GUI_17 ".
  댓글 수: 3
Sean de Wolski
Sean de Wolski 2011년 5월 16일
Set two timers at 10 seconds each, with each having its own callback, one starting 5 seconds after the other.
Paulo Silva
Paulo Silva 2011년 5월 16일
No need for two timers, he can just use the StartDelay argument for the first 5 seconds.

댓글을 달려면 로그인하십시오.


Paulo Silva
Paulo Silva 2011년 5월 16일
function GuiFun
fig=figure;
GuiButton = uicontrol('Style','pushbutton','String','PushToStart',...
'Position',[315,220,70,25],...
'Callback',@StartTimer);
t = timer('TimerFcn',@TimerFun, 'ExecutionMode',...
'fixedSpacing','Period',10,'StartDelay',5);
Val=1;
function StartTimer(a,b)
start(t)
disp('Timer Started, wait 5 seconds')
set(GuiButton,'String','Wait')
end
function TimerFun(a,b)
%protection against user closing the figure while timer is running
if ~ishandle(fig)
stop(t)
disp('User closed the figure while timer was running')
disp('Timer stopped')
return
end
set(GuiButton,'String',['part' num2str(Val)])
Val=Val+1;
if Val>3
stop(t);
set(GuiButton,'String','End')
disp('Timer Stop after 2 periods')
else
disp('wait 10 seconds')
end
end
end
  댓글 수: 1
Sharmen
Sharmen 2011년 5월 16일
thanks paulo

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by