How can I put a timer in my GUI?

조회 수: 1 (최근 30일)
Collegue
Collegue 2017년 3월 28일
댓글: Collegue 2017년 3월 28일
I want a code that is counting all the time since I press the push button. If the time is 3 s I want to display a message if the time is between 3s and 6s I want another message and between 6s and 20s the final message.
Could someone help me?

채택된 답변

KSSV
KSSV 2017년 3월 28일
t1 = tic ;
count =0 ;
while count ==0
if abs(3-toc(t1))<=10^-5
disp('time is 3S') ;
elseif toc(t1)>3 && toc(t1)<6
disp('time is between 3S and 6S')
elseif toc(t1)>6 && toc(t1)<20
disp('time between 6S and 20S')
end
end
toc(t1)
  댓글 수: 5
KSSV
KSSV 2017년 3월 28일
You may need not to use this while loop....when you press button 1, call the tic, when you press the second button call the toc...it gives time..depending on it's value display the message.
Collegue
Collegue 2017년 3월 28일
This would be okey?
function firstbutton_Callback(hObject, eventdata, handles)
setappdata(H.Fig, 'Started', now);
function secondbutton_Callback(hObject, eventdata, handles)
elapsed = (now - getappdata(H.Fig, 'Started')) * 86400;
if elapsed <= 3.0
set(handles.text2, 'String', '<= 3');
elseif elapsed <= 6.0
set(handles.text2, 'String', '<= 6');
elseif elapsed <= 20.0 % Or simply "else"?
set(handles.text2, 'String', 'final message');
else
set(handles.text2, 'String', 'too slow');
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by