Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
display a tic toc timer in a gui window

Subject: display a tic toc timer in a gui window

From: David

Date: 6 Aug, 2010 13:57:04

Message: 1 of 4

Hi! I am new to programming and I have a question. I have a GUI window that I created without using GUIDE. There is a start Timer push button and an edit window next to it. When the Start Timer button is pressed it starts a timer using tic. I want the running elapsed time to be shown in the edit window, like a timer on a watch. I can not seem to get this to work, any suggestions? Additionally is there a way to stop the tic timer from running in the background?
Thank you,
Nicole

Subject: display a tic toc timer in a gui window

From: Sean

Date: 6 Aug, 2010 14:34:04

Message: 2 of 4

"David " <drjengr@aol.com> wrote in message <i3h4bg$8vp$1@fred.mathworks.com>...
> Hi! I am new to programming and I have a question. I have a GUI window that I created without using GUIDE. There is a start Timer push button and an edit window next to it. When the Start Timer button is pressed it starts a timer using tic. I want the running elapsed time to be shown in the edit window, like a timer on a watch. I can not seem to get this to work, any suggestions? Additionally is there a way to stop the tic timer from running in the background?
> Thank you,
> Nicole

Use a timer function (doc timer) that updates the 'String' property of your edit box every differential time period you want.

Eg. if you want it to update every 1 second:
%%%
toc_it = @set(handles.editbox,'String',toc);
t = timer('TimerFcn',toc_it, 'Period', 1.0);
tic
start(t);
%%%

Subject: display a tic toc timer in a gui window

From: David

Date: 6 Aug, 2010 14:57:04

Message: 3 of 4

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i3h6gs$12c$1@fred.mathworks.com>...
> "David " <drjengr@aol.com> wrote in message <i3h4bg$8vp$1@fred.mathworks.com>...
> > Hi! I am new to programming and I have a question. I have a GUI window that I created without using GUIDE. There is a start Timer push button and an edit window next to it. When the Start Timer button is pressed it starts a timer using tic. I want the running elapsed time to be shown in the edit window, like a timer on a watch. I can not seem to get this to work, any suggestions? Additionally is there a way to stop the tic timer from running in the background?
> > Thank you,
> > Nicole
>
> Use a timer function (doc timer) that updates the 'String' property of your edit box every differential time period you want.
>
> Eg. if you want it to update every 1 second:
> %%%
> toc_it = @set(handles.editbox,'String',toc);
> t = timer('TimerFcn',toc_it, 'Period', 1.0);
> tic
> start(t);
> %%%

Thanks, I really appreciate it! I had a tic timer running in the background and when i added that code it updated the Edit window every time I pressed the start timer button. When I restarted Matlab and did not have a timer running already I received an error message saying that I must run tic first.

Subject: display a tic toc timer in a gui window

From: Sean

Date: 6 Aug, 2010 15:19:04

Message: 4 of 4

"David " <drjengr@aol.com> wrote in message <i3h7s0$qou$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i3h6gs$12c$1@fred.mathworks.com>...
> > "David " <drjengr@aol.com> wrote in message <i3h4bg$8vp$1@fred.mathworks.com>...
> > > Hi! I am new to programming and I have a question. I have a GUI window that I created without using GUIDE. There is a start Timer push button and an edit window next to it. When the Start Timer button is pressed it starts a timer using tic. I want the running elapsed time to be shown in the edit window, like a timer on a watch. I can not seem to get this to work, any suggestions? Additionally is there a way to stop the tic timer from running in the background?
> > > Thank you,
> > > Nicole
> >
> > Use a timer function (doc timer) that updates the 'String' property of your edit box every differential time period you want.
> >
> > Eg. if you want it to update every 1 second:
> > %%%
> > toc_it = @set(handles.editbox,'String',toc);
> > t = timer('TimerFcn',toc_it, 'Period', 1.0);
> > tic
> > start(t);
> > %%%
>
> Thanks, I really appreciate it! I had a tic timer running in the background and when i added that code it updated the Edit window every time I pressed the start timer button. When I restarted Matlab and did not have a timer running already I received an error message saying that I must run tic first.

To elaborate:
Since you want it to continuously update:
T = timer('TimerFcn',myfun,'Period', 1,'ExecutionMode','FixedRate');
set the execution mode to fixedrate
also in my function above, you'll most likely need this:
toc_it = @(obj,evnt)set(handles.editbox,'String',toc);

Good Luck

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us