Main Content

split

Split calendar duration into numeric and duration units

Description

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

example

Examples

collapse all

Create a calendarDuration array.

T = calmonths(15:17) + caldays(8) + hours(1.2345)
T = 1x3 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'})
m = 1×3

    15    16    17

d = 1×3

     8     8     8

t = 1x3 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'})
y = 1×3

     1     1     1

m = 1×3

     3     4     5

d = 1×3

     8     8     8

t = 1x3 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 a calendarDuration 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 the calendarDuration array, t.

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

ValueUnits 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

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.

Version History

Introduced in R2014b