How to split datetime vector into a numerical Matrix?

조회 수: 2 (최근 30일)
Enrico Gambini
Enrico Gambini 2021년 1월 28일
편집: Stephen23 2021년 1월 28일
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에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by