Get a subset of columns from a timeseries object as a timeseries
43 views (last 30 days)
I have a timeseries containing data for 4 variables:
Ts = 0.2; nT = 50;
t = Ts*(0:nT-1)';
u1 = 50*idinput(nT);
u2 = 50*idinput(nT);
u3 = 50*idinput(nT);
u4 = 50*idinput(nT);
u = timeseries([u1 u2 u3 u4],t);
I see there is a function called getsamples to get a subset of the data samples.
E.g. to get the first data point:
Time: [1x1 double]
TimeInfo: [1x1 tsdata.timemetadata]
Data: [1x4 double]
DataInfo: [1x1 tsdata.datametadata]
More properties, Methods
But how do I get a subset of the columns as a timeseries?
u1 = ... % ?
E.g. what if I want to plot just u1?
Obviously, I can do this:
But isn't there a simpler way similar to how I would plot a timeseries with only one variable?
plot(u(:,1)) % indexing like this does not work
dpb on 4 Apr 2021
Edited: dpb on 4 Apr 2021
"But isn't there a simpler way similar to how I would plot a timeseries with only one variable?"
Once you made a timeseries object out of a multi-dimensional array, no. The .Data property is a 2D array and so you must subscript the array to refer to only a single column (or subset of columns) just like any other array.
I've found the timeseries object to be more cumbersome than the features it offers owing to the way interaction with it is built; I'd probably just revert to a regular timetable instead, unless you do have the one or two specific things the timeseries supports like the event.
But, the object is constructed such that all the data associated with it is either a vector or a 2D array, it doesn't have the concept of there being separate but associated timeseries variables. That can only be done in a timetable
As noted, at least so far I've failed to find sufficient added features in the timeseries to be able to have found a use for it for either anything I've tried to do myself or even to answer any Q? posed here (other than just syntax issues like this one that (almost?) all of which have resulted in suggesting other solutions are more easily implemented than by continuing to fight the timeseries limitations/design).