isregular - Determine if input times are regular with respect to time or calendar

        unit - MATLAB ([original](http://www.mathworks.com/help/matlab/ref/timetable.isregular.html)) ([raw](?raw))

Determine if input times are regular with respect to time or calendar unit

Syntax

Description

[tf](#bvdhi2s-TF) = isregular([D](#bvdhi2s-TT)) returns 1 (true) if the input times are_regular_. Otherwise, it returns 0 (false). The input array D is regular if its times are in a sequence that is strictly monotone (either increasing or decreasing) with a unique time step.

The input argument D can be a:

This syntax is equivalent to isregular(D,'time').

example

[tf](#bvdhi2s-TF) = isregular([D](#bvdhi2s-TT),[timeUnit](#bvdhi2s-unit)) determines if D is regular with respect to the specified time or calendar unit.

For example, D might be regular with respect to months, but irregular with respect to exact elapsed time because different months can have different numbers of days. To determine if D is regular with respect to months, specify timeUnit as'months'.

example

[[tf](#bvdhi2s-TF),[dt](#bvdhi2s-dt)] = isregular(___) returns dt, the time step between consecutive times. If D is regular, thendt is either a duration value or acalendarDuration value. If D is not regular, then dt is a NaN value.

example

Examples

collapse all

Create a duration vector by using the seconds function.

D = 1×5 duration 1 sec 2 sec 3 sec 4 sec 5 sec

Test D using the isregular function. D is regular because the time interval between consecutive elements is always the same.

Change the last element of D.

D = 1×5 duration 1 sec 2 sec 3 sec 4 sec 10 sec

D is no longer regular.

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

First, create a timetable whose row times are the first five months of the year 2016, stored as datetime values. Add the monthly price of a stock as a timetable variable.

StockPrice = [109.0;107.82;113.17;128.01;116]; M = timetable(datetime(2016,1:5,3)',StockPrice)

M=5×1 timetable Time 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 if M is a regular timetable.

M is not regular with respect to time because the first five months have different numbers of days. Therefore, the exact amount of time between consecutive row times differs from row to row. You can use the diff function to calculate the differences in the time steps between consecutive times in M. The differences are duration values, formatted to display the time steps as hours, minutes, and seconds.

T = 4×1 duration 744:00:00 696:00:00 744:00:00 720:00:00

M is regular with respect to months because the time interval between the row times of M is always one calendar month.

tf = isregular(M,'months')

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 timetable Time Pulse ______ _____

0 min      72  
15 min     75  
30 min     80  
45 min     73  
60 min     69  

TT is a regular timetable.

Input Arguments

collapse all

Input variable, specified as a timetable, a datetime vector, or a duration vector.

Time or calendar unit, specified as a character vector or string scalar.isregular determines if the consecutive times ofD are regular to the time or calendar unit specified by timeUnit. The table lists the units that you can specify.

Time or Calendar Unit Description
'years' Regular to the year
'quarters' Regular to the quarter
'months' Regular to the month
'weeks' Regular to the week
'days' Regular to the day
'time' (default) Regular with respect to time

Output Arguments

collapse all

True or false, returned as a logical 1 if the input is regular and a logical 0 if it is not.

Time step between consecutive times, returned as aduration or calendarDuration scalar. If the input is not regular, then dt is aNaN value.

Tips

tf = isregular(TT,'month')

Extended Capabilities

expand all

Theisregular function fully supports tall arrays. For more information, see Tall Arrays.

Version History

Introduced in R2016b

expand all

You can use the isregular function to determine if a timetable, datetime vector, or duration vector is regular. In previous releases, you can use isregular only on a timetable.