delete

Class: timer

Remove timer object from memory

Syntax

Description

example

delete(t) removes the timer object, t, from memory. If t is an array of timer objects, delete removes all the objects from memory.

When you delete a timer object, it becomes invalid and you cannot reuse it. If multiple references to a timer object exist in the workspace, deleting the timer object invalidates the remaining references. To remove invalid timer objects references from the workspace, use the clear command.

Input Arguments

t

Object of class timer.

Examples

expand all

Create and start a timer that generates a 10-by-10 array of random numbers.

t = timer('TimerFcn','rand(10);'); 
start(t)

Delete the timer from memory.

delete(t)

Call the whos function to see if a reference still exists in the workspace.

whos
  Name       Size            Bytes  Class     Attributes

  ans       10x10              800  double              
  t          1x1               104  timer               

Try to restart the timer.

start(t)
Error using timer/start (line 27)
Invalid timer object. This object has been deleted and should be removed from your workspace using CLEAR.

The timer cannot be restarted.

Clear the timer object reference from the workspace.

clear t

Use delete with the timerfind method to remove all visible timers from memory. This is an alternative to deleting individual timers by variable name.

Create and start three timers that compute the sine, cosine and tangent of pi/4.

t1 = timer('TimerFcn','sin(pi/4);'); 
t2 = timer('TimerFcn','cos(pi/4);'); 
t3 = timer('TimerFcn','tan(pi/4);');

Delete the timers from memory using timerfind. This removes all visible timer objects from memory.

delete(timerfind)
Warning: You are deleting one or more running timer objects. MATLAB has automatically stopped them before deletion.

Tips

  • Use the isvalid method to determine if a timer object exists in memory, but is not cleared from the workspace.

  • Use the timerfind and timerfindall methods to return timer objects currently existing in memory. This approach is useful if the reference to the timer object is cleared from the workspace (using the clear command), but not deleted from memory.

Introduced before R2006a