Change Time Series Object Time format to 'HH:MM:SS.FFF' from having an original Time format of seconds
11 views (last 30 days)
Show older comments
I am working with data which has a timestamp. Each data has it's own timestamp which may not be the same as the next (since the data is coming over from various serial BUSes). This timestamp is obtained in seconds but it is needing to be in the format 'HH:MM:SS.FFF' when the user wants to see it. For example, wanting to see the data from time ranges 10:32:55.999 to 12:33:05.239 and having a list with these data values next to each corresponding time values. I am able to use datestr(timeSeriesObject.Time, 'HH:MM:SS.FFF') to convert a time in seconds to a time in that format but I can't 'shove' that new time format into my timeSeriesObject.Time because it has become a #by12 character vector (12 because of the 12 characters in 'HH:MM:SS.FFF'). I have Matlab 2016a, if I had Matlab R2016b or later I believe there's a way to convert all the characters into a STRING and perhaps it may work. I tried m1copy.TimeInfo.Format = 'HH:MM:SS.FFF'; and it just changes the text displayed in the "Common Properties: Format: ''" of the time Series object TimeInfo.
My m1 timeseriesObject can look like this for example:
m1time = (28576.6010220000:1:28585.6010090000)';
m1data = = (1:2:length(tsam2)*2)';
m1 = timeseries(m1data ,m1time );
>> m1.Time = datestr(m1.Time, 'HH:MM:SS.FFF');
Error using timeseries.tsChkTime (line 545)
Time vector must be a 1xn or nx1 vector.
Error in tsdata.timemetadata/reset (line 260)
t = timeseries.tsChkTime(t);
Error in timeseries/set.Time (line 143)
this.TimeInfo =
reset(this.TimeInfo,input);
Instead of listing a bunch of timeseries with their times in seconds:
Time (seconds) | Data | Data2 ...
28576.6010220000 1 2.3
.
.
.
Needing to display like this:
Time (HH:MM:SS) | Data | Data2 ...
14:25:28.301 1 2.3
.
.
.
Now of course what I've just listed assumes a common time Base which is not always the case. If they do not share a common time base I plan to use timeseries method "synchronize" to help me.
After I resolve the above issue, I need to be able to plot this data with the horizontal ("x-axis") showing the times in the 'HH:MM:SS.FFF' format.
Thank you for your time and help.
0 Comments
Answers (1)
Walter Roberson
on 13 Feb 2018
It appears you might have to convert your time information to absolute strings before creating the timeseries
The properties hint that you might possibly be able to set the timeseries TimeInfo.Format property but that you would also have to set the TimeInfo.StartDate to make use of it -- that the Format is possibly ignored for completely relative values. In my playing I was not able to find the combination of properties to get a relative time formatted.
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!