How to split datetime vector into a numerical Matrix?

3 次查看(过去 30 天)
Hello to everybody, my goal is to get a matrix of numbers starting from a timeseries which was created by the command "datetime".
a=datetime(1981,1,1);
b=datetime(1983,31,1);
t1=a:b;
t2=datetime(t1,'Format','yyyy-M-d');
So t2 will be a (1643x1) datetime vector in the format [1981-1-1 ; 1981-1-2 ; 1981-1-3 ;......], i'd really like to trasform that vector into a numerical matrix done in this format:
[1981,1,1 ;1981,1,2 ;1981,1,3 ;.....].
I hope that my question is clear. Thank you!

采纳的回答

Stephen23
Stephen23 2021-1-28
编辑:Stephen23 2021-1-28
M = [t2.Year(:),t2.Month(:),t2.Day(:)]
M = 1643×3
1981 1 1 1981 1 2 1981 1 3 1981 1 4 1981 1 5 1981 1 6 1981 1 7 1981 1 8 1981 1 9 1981 1 10
or use the first three columns:
M = datevec(t2)
M = 1643×6
1981 1 1 0 0 0 1981 1 2 0 0 0 1981 1 3 0 0 0 1981 1 4 0 0 0 1981 1 5 0 0 0 1981 1 6 0 0 0 1981 1 7 0 0 0 1981 1 8 0 0 0 1981 1 9 0 0 0 1981 1 10 0 0 0

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by