split
将日历持续时间拆分为数值和持续时间单位
说明
示例
拆分日历持续时间数组
创建一个 calendarDuration
数组。
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
获取月、日和时间。
[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
获取年、月、日和时间。
[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
当同时请求年和月份时,split
会将大于 12 的月份值进位到年值。
输入参数
t
— 输入日历持续时间
calendarDuration
数组
输入日历持续时间,指定为 calendarDuration
数组。
数据类型: calendarDuration
units
— 日期时间单位
字符向量 | 字符向量元胞数组 | 字符串数组
日期时间单位,指定为一个字符向量、字符向量元胞数组或字符串数组。仅当第一个输入参量为 calendarDuration
数组 t
时才指定 units
。
单位可以是下表中的一个或多个值。
值 | 单位 t 拆分为 |
---|---|
'years' | 年 |
'quarters' | 季度 |
'months' | 月 |
'weeks' | 周 |
'days' | 天 |
'time' | 时间,格式为 hours:minutes:seconds |
必须从最大到最小指定日期时间单位。例如,{'years','months'}
有效,但 {'months','years'}
无效。
示例: split(t,{'years','months','days'})
数据类型: char
| cell
| string
输出参量
X1,X2,...
— 输出数值和 duration
值
数组
输出数值和 duration
值,以数组的形式返回。split
在数值数组中返回年、月、日值,在 duration
数组中返回时间值。
数据类型: double
| duration
扩展功能
tall 数组
对行数太多而无法放入内存的数组进行计算。
此函数完全支持 tall 数组。有关详细信息,请参阅 tall 数组。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
版本历史记录
在 R2014b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)