update date and time in gui

3 views (last 30 days)
Stalin Samuel
Stalin Samuel on 21 Jan 2016
Commented: Rainaire Hansford on 25 May 2019
function demo1()
H.f = figure('Name','DEMO1');
set(H.f,'Units','Pixels','Position',get(0,'ScreenSize'));% adjust figure size as per the screen size
H.pb1 = uicontrol('style','push',...
'units','pixels',...
'position',[400 800 280 30],...
'fontsize',14,...
'string', datestr(now)); % datestr(now) is used to get current date and time
end
Now my intention is to update the date and time and it should be run like a real time clock

Answers (1)

Walter Roberson
Walter Roberson on 21 Jan 2016
You are going to want to use a timer to update the graphics. Odd that you would put it on a pushbutton rather than as a uicontrol('style','text'), but whatever.
The timer that does the update is going to need to get the handle of the graphics object to update. It would find that easier if you returned your H out of your function, or if you had at least added a Tag to the uicontrol so that it could (inefficiently but functionally) search all the graphics objects by name. As it is now, the timer is going to have to locate the figure by name and then dig inside the figure to find the uicontrol...
  1 Comment
Rainaire Hansford
Rainaire Hansford on 25 May 2019
Hi Stalin,
Any way to apply your function on a script?

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps 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!