How to display a running timer in MATLAB Design App

35 views (last 30 days)
Dear Coder, I have design a simple app using App Design. The App supposed to show a time lapse while some other activity are running simultanously. Other thread have discussed about the implementation of time lapse under App design by the Design App such as link or link.
However, im still unable to replicate the solution given in these thread.
Hence, I tried something like below,
while app1.StarttimelapseButton.Value==1
T2 = clock;
time_elapsed = etime(T2,T1);
app1.TimeLapseEditField.Value=sprintf('%.6f',time_elapsed );
drawnow
end
% Next lines
% Function responsible for the execution of the "Other activity"
However, the code execution stuck in the while loop if using the above code.
May I know how to implement a timer in AppDesigner. The m and mlapp files that I created can be found this link.
Thanks in advance for the time to entertain this problem
  4 Comments
Mohammad Sami
Mohammad Sami on 26 Jan 2020
Edited: Mohammad Sami on 26 Jan 2020
No. I am suggesting that your UI update needs to be from inside the "other activity" code. If your other activity is primarily executing a for / while loop, you can also put in a line to update the UI.
If not, you can update the UI after completing certain appropriate "milestones" in your "other activity" code.
Mohammad Sami
Mohammad Sami on 26 Jan 2020
Also another option to show "activity" in appdesigner is to use uiprogressdlg. This will show a progress bar, which you can use to show the milestones / progress on.
progrssbar = uiprogressdlg(app.UIFigure);
progrssbar.Value = 0.1;
progrssbar.Message = 'Doing A';
% activity A
progrssbar.Value = 0.5;
progrssbar.Message = 'Doing B';
% activity B
progrssbar.Value = 1;
progrssbar.Message = 'Finished';
close(progrssbar);

Sign in to comment.

Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!