startat - Schedule timer to fire at specified time - MATLAB (original) (raw)
Schedule timer to fire at specified time
Syntax
Description
Use this function to add a delay between when a timer starts and when the timer callback function, timerFcn
, will begin firing.
startat([t](#mw%5Fede07102-ace7-4170-9001-bb1e4db5b36b),[firingTime](#mw%5Fb0193c36-5030-433f-a905-0d79999815e4))
schedules timer t
to fire at specified time,firingTime
. A timer fires by executing the callback function,timerFcn
. firingTime
must be within 25 days of the current time. Note that if t
has start callback function,startFcn
, this function will fire when startat
is called and not at the time specified by firingTime
.
- If
t
is an array of timers andfiringTime
is a scalar,startat
sets all the timers to fire at the specified time. - If
t
is an array of timers andfiringTime
is an array of the same size ast
,startat
sets each timer to fire at the corresponding time.
startat(t,[Y,M,D](#mw%5F3221554a-59c8-4c56-b663-fe135c8375d4))
starts the timer and schedules execution of TimerFcn
at the year (Y
), month (M
), and day (D
) that you specify.
startat(t,[Y,M,D,H,MI,S](#mw%5Fc4029002-5bbe-4271-a7e7-ad0fbf3ec989))
also specifies the hour (H
), minute (MI
), and second (S
) that you specify.
Examples
Start Timer in 2 Seconds
Create a timer that displays messages at start time and firing time.
t = timer('TimerFcn', @(,)disp('Fired.'), ...
'StartFcn', @(,)disp('Started.'));
Set the timer to fire 2 seconds from the present time by using adatetime
and adding a duration
of 2 seconds.
two = seconds(2); % a two second duration fTime = datetime + two startat(t,fTime);
fTime =
datetime
14-Aug-2020 16:30:50
Started. Fired.
Wait for the timer to fire, and then delete the timer.
Start Timer Using Year, Month, Day
Create a timer that displays messages at start time and firing time.
t = timer('TimerFcn', @(,)disp('Fired.'), ...
'StartFcn', @(,)disp('Started.'));
Schedule the timer to start 2 days from present at 00:00:00.
[Y, M, D, H, MI, S] = datevec(now+2); startat(t,Y,M,D)
Manually stop and delete the timer.
Input Arguments
t
— timer object
timer object | array of timer objects
Timer to start, specified as a timer object or array of timer objects.
Example: startat(t,firingTime)
firingTime
— Start time of timer
datetime
array | serial date number | character representation of date format | date vector
Time at which the timer is to fire, specified as a datetime
array, serial date number, character representation of date format, or a date vector.firingTime
can be a single date or an array of dates with the same number of values as timer objects in t
.
- A
datetime
array stores values that represent points in time, including a date and a time of day. Aduration
can be added to adatetime
by using the+
operator. For more information, see Represent Dates and Times in MATLAB. - A serial date number indicates the number of days that have elapsed since 1-Jan-0000 (starting at 1). For additional information about serial date numbers, see datenum.
- To specify character representation of dates, use these date formats defined by the datestr function: 0, 1, 2, 6, 13, 14, 15, 16, or 23. These numeric identifiers correspond to formats defined by the
formatOut
property of thedatestr
function. Dates with two-character years are interpreted to be within the 100 years centered on the current year. - Date vectors are specified as an
m-by-6
orm-by-3
matrix containingm
full or partial date vectors, respectively. A full date vector has six elements indicating year, month, day, hour, minute, and second, in that order. A partial date vector has three elements indicating year, month, and day, in that order.
Example: startat(t,firingTime)
Y,M,D
— Year, month, day
numeric scalars separated by commas
Time at which the timer object is to fire, specified as numbers indicating the year (Y
), month (M
), and day (D
). Month values less than 1 are set to 1. Other arguments can wrap and have negative values.
Example: startat(t,Y,M,D)
Y,M,D,H,MI,S
— Year, month, day, hour, minute, second
numeric scalars separated by commas
Time at which the timer object is to fire, specified as numbers indicating the year (Y
), month (M
), day (D
), hour (H
), minute (MI
), and second (S
) specified. Month values less than 1 are set to 1. Other arguments can wrap and have negative values.
Example: startat(t,Y,M,D,H,MI,S)
Version History
Introduced before R2006a