Inserting a timer in standalone application.

조회 수: 2 (최근 30일)
sanchit ingale
sanchit ingale 2017년 6월 26일
편집: sanchit ingale 2017년 7월 14일
I have created a standalone application in Matlab using guide feature and Matlab Compiler. I need to insert a timer to get the time for which the application was used every time. How can I implement this in my application ?
  댓글 수: 2
Jan
Jan 2017년 6월 26일
What should the "timer" do? Display the elapsed time every second or store the used time on the disk, when the application is closed? What does "which the application was used every time" exactly mean?
sanchit ingale
sanchit ingale 2017년 7월 14일
Hi Jan,
The timer should just be displayed during the application is running. And it should increment by 1 second.

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

답변 (1개)

Walter Roberson
Walter Roberson 2017년 7월 14일
편집: Walter Roberson 2017년 7월 14일
First ensure that you have a uicontrol style 'text' with tag 'timer_display' .
In the figure CreateFcn callback,
fig = hObject;
start_time = now();
txtbox = findobj(fig, 'tag', 'timer_display');
timer_obj = timer('Period', 1, 'TimerFcn', @(hobject, event) set(txtbox, 'string', datestr(now-start_time, 'HH:MM:SS')));
set(fig, 'UserData', timer_obj); %do not let it get deleted
start(timer_obj);
Note: this timer will not get updated at all during some long-running computations. For example if you use the mldivide operator for large matrices then a high performance library is called that does not support timers.
Note: with the form of the code given here, the text box will get updated during graphics callbacks, but the display might not get updated immediately. To have the text updated immediately, you need to add in a drawnow() call, which unfortunately would require that you create a real function to be called-back (anonymous functions cannot chain calls that do not produce output.)
  댓글 수: 1
sanchit ingale
sanchit ingale 2017년 7월 14일
편집: sanchit ingale 2017년 7월 14일
Thanks for the input. The timer is appearing, however there is no increment. Timer stays at '00:00:00'. There is no error on running the GUI application.

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

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by