How to split datetime vector into a numerical Matrix?

2 visualizaciones (últimos 30 días)
Enrico Gambini
Enrico Gambini el 28 de En. de 2021
Editada: Stephen23 el 28 de En. de 2021
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!

Respuesta aceptada

Stephen23
Stephen23 el 28 de En. de 2021
Editada: Stephen23 el 28 de En. de 2021
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

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by