creating time date matrix

1 回表示 (過去 30 日間)
vedesh Mohit
vedesh Mohit 2018 年 2 月 7 日
コメント済み: vedesh Mohit 2018 年 2 月 10 日
I want to create an hourly date/time (366 x24) matrix starting from 2000-01-01 and ending 2000-12-31. It must start at midnight 00:00 and end at 23:00 for each day. I would also like each new day to begin in a new row. How do i do that?

採用された回答

Akira Agata
Akira Agata 2018 年 2 月 8 日
One possible solution would be like this.
T = datetime(2000,1,1):hours(1):datetime(2000,1,1,23,0,0);
T = repmat(T,366,1);
T = T + days(repmat((0:365)',1,24));
  1 件のコメント
vedesh Mohit
vedesh Mohit 2018 年 2 月 8 日
If I have extend the matrix starting from 2000-01-01 and ending 2015-03-31. How could that be done.?

サインインしてコメントする。

その他の回答 (1 件)

Akira Agata
Akira Agata 2018 年 2 月 8 日
OK, here is more generalized script. Writing this way, you can flexibly change the starting and ending date, and generate the corresponding matrix.
startDay = datetime(2000,1,1);
endDay = datetime(2015,12,31);
T = startDay + hours(0:23);
nDays = days(endDay - startDay);
T = repmat(T,nDays+1,1);
T = T + days(repmat((0:nDays)',1,24));
  1 件のコメント
vedesh Mohit
vedesh Mohit 2018 年 2 月 10 日
Thank you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalendar についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by