Main Content

isregular

Determine if timetable is regular with respect to time or calendar unit

Description

example

tf= isregular(TT,timeComponent)returns1(true) if timetableTTisregularwith respect to the specified time or calendar unit. Otherwise, it returns0(false). A timetable is regular if its row times increase or decrease monotonically by the same time step.

  • If the row times ofTTaredatetimevalues, then the time steps between them might be regular with respect to a calendar unit such as months, but irregular with respect to exact elapsed time. Specify the time or calendar unit by using thetimeComponentinput argument.

    For example, if the row times are regular monthlydatetimevalues, andtimeComponentis'month', thenisregularreturns1. But iftimeComponentis'time', thenisregularreturns0because different months can represent different lengths of time.

  • If the row times aredurationvalues, then specifytimeComponentas'time'or use the next syntax. Thedurationdata type does not represent times using calendar units.

example

tf= isregular(TT)相当于isregular(TT,'time').

example

[tf,dt] = isregular(___)returnsdt, the time step between row times. IfTTis regular, thendtis either adurationvalue or acalendarDurationvalue. IfTTis not regular, thendtis aNaNvalue.

Examples

collapse all

Create a timetable by using a monthly time vector. Determine whether it is regular with respect to time, and then with respect to months.

Create a timetable whose row times are the first five months of the year2016. Add the monthly price of a stock as a table variable.

StockPrice = [109.0;107.82;113.17;128.01;116]; M = timetable(datetime(2016,1:5,3)',StockPrice)
M=5×1 timetableTime StockPrice ___________ __________ 03-Jan-2016 109 03-Feb-2016 107.82 03-Mar-2016 113.17 03-Apr-2016 128.01 03-May-2016 116

Determine whetherMis a regular timetable.

TF = isregular(M)
TF =logical0

Mis not regular because the first five months have different numbers of days. You can use thedifffunction to calculate the differences in the time steps between consecutive times inM. The differences are durations, formatted to display the time steps as hours, minutes, and seconds.

D = diff(M.Time)
D =4x1 duration744:00:00 696:00:00 744:00:00 720:00:00

Determine whetherMis regular with respect to months by specifying'month'as the unit of measure.

TF = isregular(M,'months')
TF =logical1

Create a timetable. Determine if it is regular, and then return the size of the time step if it is.

Time = [minutes(0):minutes(15):minutes(60)]'; Pulse = [72 75 80 73 69]'; TT = timetable(Time,Pulse)
TT=5×1 timetableTime Pulse ______ _____ 0 min 72 15 min 75 30 min 80 45 min 73 60 min 69
[TF,dt] = isregular(TT)
TF =logical1
dt =duration15 min

TTis a regular timetable.

Input Arguments

collapse all

Input timetable.

Time or calendar unit, specified as a character vector or string scalar.isregulardetermines if the row times ofTTare regular to the time or calendar unit specified bytimeComponent. The table lists the units that you can specify.

Time or Calendar Unit

Description

'years'

定期对the year

'quarters'

定期对the quarter

'months'

定期对the month

'weeks'

定期对the week

'days'

定期对the day

'time'(default)

Regular with respect to time

Output Arguments

collapse all

True or false, returned as a logical1if the row times are regular and a logical0if they are not.

Time step between row times, returned as adurationorcalendarDurationvalue. If the timetable is not regular, thendtis aNaNvalue.

Tips

  • In certain cases, you can create a timetable while specifying a regular time step between row times, and yet the resulting timetable is irregular. This result occurs when you specify the time step by using a calendar unit of time and there is a row time that introduces an irregular step. For example, if you create a timetable with a time step of one calendar month, starting on January 31, 2019, then it is irregular with respect to months.

    stime = datetime(2019,1,31); tstep = calmonths(1); TT = timetable('Size',[3 1],'VariableTypes',{'double'},...'TimeStep',tstep,'StartTime',stime); tf = isregular(TT,'month')
    tf = logical 0

    There are other cases where irregularities are due to shifts from Daylight Saving Time (DST) or to row times that are leap seconds. This table specifies the row time values and time steps that can produce irregular timetables unexpectedly.

    Row Time Value

    Time Step

    Start time specified as the 29th, 30th, or 31st day of the month.

    Number of calendar months or quarters.

    开始时间指定为2月29日。

    Number of calendar years.

    Any row time occurring between 1:00 a.m. and 2:00 a.m. on a day shifting from DST to standard time (when row times are specified as datetime values whose time zone observes DST). Number of calendar days or months.

    Any row time that is a leap second (when row times are specified as datetime values whose time zone is theUTCLeapSecondstime zone). For the list of leap seconds, seeleapseconds.

    Time step specified in any calendar unit (days, weeks, months, quarters, or years).

Extended Capabilities

Introduced in R2016b