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

15 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

Rik
Rik el 5 de Nov. de 2021
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

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by