How do you create an array of date times given a starting date and number of days?

15 ビュー (過去 30 日間)
Hamza Ibad
Hamza Ibad 2021 年 11 月 5 日
コメント済み: Hamza Ibad 2021 年 11 月 5 日
I want to start at Jan/1/1900 and given the length of a vector, generate a vector of dates with 1 day intervals
e.g.
Vector1 = [1 2 3 4 5 6]
I want to create a datetime vector that will ouput
Datetimevector = [Jan/1/1900, Jan/2/1900, Jan/3/1900, Jan/4/1900, Jan/5/1900, Jan/6/1900]
I've tried to search the syntax for something that will give this output but I can't seem to find it.
Thanks in advance!

採用された回答

Rik
Rik 2021 年 11 月 5 日
Vector1=1:5;
Datetimevector = datetime(1900,1,1)+days(1:numel(Vector1))
Datetimevector = 1×5 datetime array
02-Jan-1900 03-Jan-1900 04-Jan-1900 05-Jan-1900 06-Jan-1900

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by