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

16 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by