Get data from timeseries object for every day contained in the timeseries object

5 views (last 30 days)
Hi everyone, I have another question related to timeseries. I created a timeseries, whereas the timevector is in the datenum format. Specifically, the format I have is for example:
7.359655423611111e+05 % which corresponds to second specific data, e.g. 01-Jan-2015 10:15:00
The timeseries contains minute-wise data, hence I have 1440 data points for each day. What I would like to do now is loop through the timeseries and extract the 1440 data points for each day and put them into a cell array.
I think the logic would be to identify the unique dates among the time vector and then use the getsampleusingtime-function in a loop that may look something like this:
dates = unique(ts.Time); % whereas ts is the timeseries
dailyData = cell([1 length(dates)]) % initialize the cell array to store the data from the timeseries
for i = 1:length(dates)
dailyData{1,i} = getsampleusingtime(ts,dates(i),'AllowDuplicateTimes, true')
end
The problem I am running into is that I
  1. Don't know how to construct the unique dates array from the full datenum time vector which also contains the h,m,s-info
  2. Don't know how to query against the ts with the unique dates, because even if I had the unique dates separated, the function is likely not to provide any matches because it is also looking for a match of the h,m,s-information
Can anyone help me out? Any help is much appreciated!
  3 Comments
Benvaulter
Benvaulter on 15 Jan 2016
Yes correct, I can access all the time information from the given datenum and thereby also construct the unique dates, but how do I then fetch the data for each unique date (in the sense of 1440 data points for "01-Jan-2015", 1440 data points for 02-Jan-2015) and so forth?
jgg
jgg on 16 Jan 2016
I mean, if you have this, you should be able to do like this:
times = [735965.542361111; 735965.542372685; 735965.542384259; ...
735966.542361111; 735966.542372685];
T = datetime(datestr(times));
days = unique(T.Day);
ind = ismember(T.Day,days(1)); %get the first day
times(ind)
You can use the Day Year properties to select data with the properties you want. If you loop over the days in days you'll iteratively select every set of observations for that day. If the day alone doesn't uniquely identify this, you'll have to add on the month, year, etc, but it's the same process.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!