Using timetable versus tscollection objects
3 次查看(过去 30 天)
显示 更早的评论
I have Simulink models that log signal data using the Simulink.SimulationData.Dataset class.
I'm writing post-processing m-code that helps analyze model outputs and would like to combine the data into either a tscollection object or a timetable object, which is easier to deal with than the collection of Simulink.SimulationData.Signal objects contained in the logsout object generated by the Simulink model.
There doesn't seem to be an 'easy' way to convert the signals in logsout into a timetable object, whereas one can create a tscolleciton object rather easily:
tsCol = tscollection;
for ii=1:logsout.numElements
tsCol = tsCol.addts(logsout.getElement(ii).Values);
end
MathWorks seems to really be pushing the use of timetables through functions such as stackedplot, and tscollection objects seem to be something of an afterthought.
It there an easy way to convert a tscollection object into a timetable? Failing that, is there a way to create an empty timetable and add the signal data from the Dataset signals in a loop as shown above?
0 个评论
回答(1 个)
Corey Silva
2020-11-20
Hi Alan,
Below is a toy example where you have a timeseriescollection containing two timeseries, ts1 and ts2.
>> ts1 = timeseries(rand(5,1),'Name','ts1');
>> ts2 = timeseries(rand(5,1),'Name','ts2');
>> tsc = tscollection({ts1,ts2});
>> tt = timetable(seconds(tsc.Time),tsc.ts1.Data(:),tsc.ts2.Data(:),'VariableNames',{'ts1_Data','ts2_Data'})
tt =
5×2 timetable
Time ts1_Data ts2_Data
_____ ________ ________
0 sec 0.15761 0.14189
1 sec 0.97059 0.42176
2 sec 0.95717 0.91574
3 sec 0.48538 0.79221
4 sec 0.80028 0.95949
Hopefully this gives you enough to get started with using timetables. I would like to assure you that we are actively working on solutions to converting between timeseries objects and timetables for future releases of MATLAB.
3 个评论
Corey Silva
2020-11-23
Hi Alan,
The addvars and removevars functions can be used to add and remove variables respectively from existing timetables. I hope this helps.
Corey
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series Collections 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!