split - Split calendar duration into numeric and duration units - MATLAB (original) (raw)

Split calendar duration into numeric and duration units

Syntax

Description

[[X1,X2,...](#d126e171008)] = split([t](#d126e170886),[units](#d126e170913)) returns the calendar duration values specified in t as separate numeric arrays, one for each of the date or time units specified byunits. The number of date and time units specified byunits determines the number of output arguments.

example

Examples

collapse all

Create a calendarDuration array.

T = calmonths(15:17) + caldays(8) + hours(1.2345)

T = 1×3 calendarDuration 1y 3mo 8d 1h 14m 4.2s 1y 4mo 8d 1h 14m 4.2s 1y 5mo 8d 1h 14m 4.2s

Get the month, day, and time.

[m,d,t] = split(T,{'months','days','time'})

t = 1×3 duration 01:14:04 01:14:04 01:14:04

Get the year, month, day, and time.

[y,m,d,t] = split(T,{'years','months','days','time'})

t = 1×3 duration 01:14:04 01:14:04 01:14:04

When you request both the year and month, split carries over month values greater than 12 to the year value.

Input Arguments

collapse all

Input calendar duration, specified as acalendarDuration array.

Data Types: calendarDuration

Date and time units, specified as a character vector, a cell array of character vectors, or a string array. Specify units only when the first input argument is thecalendarDuration array,t.

The units can be one or more of the values in the table.

Value Units t Is Split Into
'years' years
'quarters' quarters
'months' months
'weeks' weeks
'days' days
'time' time, in the format hours:minutes:seconds

You must specify date and time units from largest to smallest. For example, {'years','months'} is valid, but{'months','years'} is not.

Example: split(t,{'years','months','days'})

Data Types: char | cell | string

Output Arguments

collapse all

Output numeric and duration values, returned as arrays.split returns year, month, and day values in numeric arrays and time values in duration arrays.

Data Types: double | duration

Extended Capabilities

expand all

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

Version History

Introduced in R2014b