Display real time clock in GUI
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Walter Roberson
2020-4-27
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!