How to convert serial date numbers to date and time format in a timeseries?
Show older comments
I'm trying to convert my values of Time in the format 'dd-mmm-yyyy HH:MM:SS', but somehow my time series keep changing the date.
I have a signal with a sampling frequency of 200 Hz (so 1 second "will be" 200 samples). The signal started to record at a certain date and time and I'm trying to create a timeseries to show me the "true" time and not samples (where the recording starts from zero).
% Create timeseries
ts = timeseries(mysignal);
% Set start/stop date and time of recording
start = '20-Aug-2018 07:25:13';
stop = '20-Aug-2018 11:42:54';
ts.TimeInfo.Startdate = start;
By default, my timeseries will be:
ts.Time(1) = '20-Aug-2018 07:25:13';
ts.Time(2) = '20-Aug-2018 07:25:14';
when, in reality, the date and time '20-Aug-2018 07:25:14' will only be at the 201-st sample.
I've adjusted my timeseries to fit this by doing the following:
% Convert time and date
starttime = datenum(start);
endtime = datenum(stop);
% Set a new interval
tsout = setuniformtime(ts, 'StartTime', starttime, 'EndTime', endtime);
But the date in ts is changing to:
tsout.Time(1) = '26-Aug-2018 20:13:23';
tsout.Time(end) = '26-Aug-2018 20:13:23';
How can I set a new interval and display it in the format I want? My goal is to have:
ts.Time(1) = '20-Aug-2018 07:25:13';
...
ts.Time(201) = '20-Aug-2018 07:25:14';
...
ts.Time(end) = '20-Aug-2018 11:42:54';
I also followed the same strategy as here but since my signal is quite large, datestr is very slow at making the conversion.
Thank you!
Accepted Answer
More Answers (0)
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!