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.

example

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.

example

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

collapse all

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

collapse all

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.

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