フィルターのクリア

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 Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by