How to split datetime vector into a numerical Matrix?

3 vues (au cours des 30 derniers jours)
Enrico Gambini
Enrico Gambini le 28 Jan 2021
Modifié(e) : Stephen23 le 28 Jan 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!

Réponse acceptée

Stephen23
Stephen23 le 28 Jan 2021
Modifié(e) : Stephen23 le 28 Jan 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

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by