Display real time clock in GUI

Hi all guy.
I displayed it in GUIDE matlab. it work good. However, it don't run when i callback function
other
Timer(handles);%call timer
function Timer(handles)
while find(get(0,'children')==handles.figure1)
nows = fix(clock);
timerStr = [num2str(nows(4)),':', num2str(nows(5)),':', num2str(nows(6))];
set(handles.time,'String',timerStr);
pause(1);
end

답변 (1개)

Walter Roberson
Walter Roberson 2020년 4월 27일

0 개 추천

You have an infinite loop. The pause() call permits the infinite loop to be interrupted by a GUI callback, but the code in the infinite loop will not continue running until the callback returns. Using pause(1) does not mean that 1 second later, no matter what MATLAB is doing, that control should be given back to your infinite loop.
What you should do is create a timer object that should run evern 1 second. The code for that timer object should update the GUI clock, and then should return.
I think you will find code for a clock in the File Exchange.

댓글 수: 3

ngo tung
ngo tung 2020년 4월 27일
Do you can fix it ?. It worked until i press callback other function .
And it run when i exit function. I think i put wrong position in GUI.
Thank you.
Rik
Rik 2020년 4월 27일
He already suggested the solution: use a timer object.
ngo tung
ngo tung 2020년 4월 27일
Thank you.

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2020년 4월 27일

댓글:

2020년 4월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by