Just noticed there is a new function called ts2timetable introduced in version 2021a which might be usefull for converting multiple timeseries objects into a timetable.
Get a subset of columns from a timeseries object as a timeseries
47 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bill Tubbs
am 3 Apr. 2021
Kommentiert: Bill Tubbs
am 5 Apr. 2021
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:
>> getsamples(u,1)
timeseries
Common Properties:
Name: 'unnamed'
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:
plot(u.Time,u.Data(:,1))
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
Akzeptierte Antwort
dpb
am 4 Apr. 2021
Bearbeitet: dpb
am 4 Apr. 2021
plot(u.Time,u.Data(:,1))
"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).
8 Kommentare
dpb
am 5 Apr. 2021
ADDENDUM:
iswithin is my little helper function to move the logical test to a higher level of abstraction --
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
end
Weitere Antworten (1)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!