setabstime

Sets absolute (calendar) times on a timeseries from date strings.

Category: Language Fundamentals > Data Types

Syntax

ts = setabstime(ts, dates)

Sets the time vector from a cell array of date strings, one per sample.

Description

By default a timeseries counts time as a plain number of seconds. After setabstime the times are offsets from the start date, so the series can be aligned with real calendar dates. The number of dates must equal the number of samples.

Input arguments

ts
A timeseries object.
dates
Cell array of date strings in a format understood by datestr.

Output arguments

ts
The series with absolute times; the first date becomes TimeInfo.StartDate.

Example

ts = timeseries([1 2 3]', [0 1 2]);
d = {'01-Jan-2024 00:00:00', '01-Jan-2024 00:00:01', '01-Jan-2024 00:00:02'};
ts = setabstime(ts, d);
ts.TimeInfo.StartDate
Output
ans = '01-Jan-2024 00:00:00'

See also

timeseries setuniformtime datestr resample