Generate vectors of datetime in Matlab / Octave
Generating a range of datetime data is a common data analysis and simulation task. Here we show examples of generating datetime vectors for:
datetime
Matlab “datetime” is strongly encouraged over legacy datenum(). datetime has a native ability to generate range of datetime like:
function times = datetime_range(tstart, tend, ts)
arguments
tstart (1,1) datetime
tend (1,1) datetime
ts (1,1) duration
end
dt = tstart:ts:tend
end
GNU Octave datetime
GNU Octave can use many datetime
features via the Octave-Tablicious package.
then load by:
pkg load tablicious
datenum
Generate a range of datenum times like:
function times = datetime_range(tstart, tend, ts)
% ts: seconds
times = tstart:ts/86400:tend;
end