Create timeseries from timeseries

3 次查看(过去 30 天)
Pankaj
Pankaj 2017-7-20
回答: Robert U 2017-7-21
I have a quick question to ask.
I would like to create a timeseries from a timeseries object but with given data columns. (Say there are four data types saved in different columns of timeseries; I need to extract only three columns).
I know how to do it for given time instances. One way could be that, I first extract the data and then time and then make a new timeseries. I want a quick way.
Thanks

回答(1 个)

Robert U
Robert U 2017-7-21
Hi Pankaj,
if I understand your question correctly, the quick way might be to utilize the methods provided by timeseries class. One possibility to reduce the number of data "columns" is shown below along with cropping the timeseries to a given start and end time:
% Create timeseries
time = 0:0.01:2;
for ik = 1:4
data(:,ik) = sin((2 * pi * 5 * time) + ((ik-1) * pi/2));
end
TS_initial = timeseries(data,time);
% Extract part of the timeseries
startTime = 0.5;
endTime = 1.5;
colsToExtract = [2 3 4];
if size(colsToExtract,1) > 0
% copy the original time series
TS_extract = TS_initial;
% select the data
TS_extract.Data = TS_extract.Data(:,colsToExtract);
% extract for a given time range
TS_extract = TS_extract.getsampleusingtime(startTime,endTime);
end
Kind regards,
Robert

类别

Help CenterFile Exchange 中查找有关 Time Series 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by