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:
switching off timers

Subject: switching off timers

From: Rob M

Date: 20 Nov, 2009 09:54:02

Message: 1 of 6

I'm losing reference to timer objects in the code that I'm trying to debug, and everytime I run it I have a new timer running that I'm unable to switch off which continues to call functions every minute. I can see all the timers using timerfind but that's about it.

Any ideas on how to delete all these timer objects?

Subject: switching off timers

From: Jan Simon

Date: 20 Nov, 2009 10:30:12

Message: 2 of 6

Dear Rob M!

> I'm losing reference to timer objects in the code that I'm trying to debug, and everytime I run it I have a new timer running that I'm unable to switch off which continues to call functions every minute. I can see all the timers using timerfind but that's about it.

If you see the handles of the timers with TIMERFIND, you can stop them and delete them afterwards.

A general idea would be to give the timer a specific tag and close all formerly created timers with the same tag automatically if your program starts.

Good luck, Jan

Subject: switching off timers

From: Rob M

Date: 20 Nov, 2009 11:12:04

Message: 3 of 6

Sounds like a plan to me Jan! I still can't figure out the syntax though. I have Index,ExecutionMode,Period,TimerFcn, and Name to choose from. I've been trying delete(1), delete(timer-1), delete('timer-1'), stop('timer-1').... and can't find an example usage in the help documentation.

Subject: switching off timers

From: Jan Simon

Date: 20 Nov, 2009 12:30:22

Message: 4 of 6

Dear Rob!

> Sounds like a plan to me Jan! I still can't figure out the syntax though. I have Index,ExecutionMode,Period,TimerFcn, and Name to choose from. I've been trying delete(1), delete(timer-1), delete('timer-1'), stop('timer-1').... and can't find an example usage in the help documentation.

Use TIMERFIND to get the handle of the timer. Pass this handle to the function STOP. Afterwards(!) delete the timer:
  TimerH = timerfind('Tag', 'the_magic_tag_as_defined_at_creation');
  for iTimer = 1:length(TimerH)
    stop(TimerH(iTimer));
    delete(ThimerH(iTimer));
  end

Good luck, Jan

Subject: switching off timers

From: Jos

Date: 20 Nov, 2009 15:39:19

Message: 5 of 6

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <he624u$p4l$1@fred.mathworks.com>...
* snip *
> TimerH = timerfind('Tag', 'the_magic_tag_as_defined_at_creation');
> for iTimer = 1:length(TimerH)
> stop(TimerH(iTimer));
> delete(ThimerH(iTimer));
> end

A small improvement of a splendid idea: there is no need for the for-loop, as stop and delete are vectorized (for timers).

Jos

Subject: switching off timers

From: Rob M

Date: 20 Nov, 2009 15:49:18

Message: 6 of 6

Thanks a lot guys. A sterling effort.

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