Info

This question is closed. Reopen it to edit or answer.

How do I compute a vector of date strings representing the longest time period covered by all elements of a given set of time series variables?

1 view (last 30 days)
I'm working with several time series objects, each covering different time spans, sampled at different frequencies, and with some scarce data as well.
I would like to identify the longest possible time period which is covered by all my time series variables. I realise this can be done manually, but I would like to find an elegant way to automate this. Some of my data are sampled at irregular intervals and the frequencies differ.
  1. Assuming I have already ensured homogenous sampling frequency, what is the most elegant way to compute a time vector that contains the dates which represent the above mentioned largest common time period I am looking to identify?
  2. Is there a way to do this when sampling frequencies are not homogenous and when working with scarce data, so that the time vector computed could then be used for interpolation? Which order is generally recommended and why?
Suggestions are greatly appreciated!
  3 Comments
Constantin
Constantin on 11 Sep 2014
Thank you for your swift response.
I have been using the following code to generate my time vector for the resample function:
time = datestr(datenum(repmat((1999:2013),12,1),repmat((1:12)',1,15),1))
So
repmat((1999:2013),12,1);
for the years, and
repmat((1:12)',1,15);
for the months. My output is a t by 11 characters char variable of the form 'dd-mmm-yyyy' which looks like this:
01-Jan-1999
01-Feb-1999
01-Mar-1999
...
01-Oct-2013
01-Nov-2013
01-Dec-2013
In order to synchronize my data, I would like to write a script which identifies the first and last point in time covered by each variable (the first and last object in Ts.Time) and computes a time vector like the one above, which is accepted by the resample function. I then want to resample all variables with their respective time vectors.
Afterwards, I want to use
getsampleusingtime
to extract all data for the longest period covered by all my time series into a time series collection object.
I hope I have been able to specify.
dpb
dpb on 11 Sep 2014
As an aside, you don't have to generate the full-blown intermediary matrix for datenum -- just use the vector input form -- I added the beginning/end years as variables for some generality in use:
yr1=1999; yr2=2013;
time=datestr(datenum(yr1,[1:(yr2-yr1+1)*12].',1)); % #yrs*12 months
...I would like to write a script which identifies the first and last point in time covered by each variable (the first and last object in Ts.Time)...
But there's the rub in the question and the one you didn't answer -- what's the sampling time within these time series? Are there monthly values on the first of month, just irregularly spaced or is it a time stamp that is just the real-time clock at the time the data are recorded? What granularity is significant?
The first/last points is simple -- it's simply min/max of the array of datenums or if they're presumably ordered the first/last entry of each series. It's the above detail of what's in between that's the quandary in what you're looking for...

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!