Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

split

Split calendar duration into numeric and duration units

Syntax

[X1,X2,...] = split(t,units)

Description

example

[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.

Examples

collapse all

Create a calendarDuration array.

T = calmonths(15:17) + caldays(8) + hours(1.2345)
T = 1x3 calendarDuration array
   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 = 

    15    16    17

d = 

     8     8     8

t = 1x3 duration array
   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     1     1

m = 

     3     4     5

d = 

     8     8     8

t = 1x3 duration array
   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 or a cell array of character vectors. Specify units only when the first input argument is the calendarDuration array, t.

The character vectors 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

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

Introduced in R2014b

Was this topic helpful?