How to interpolate between two vectors of timeseries and get outputs of the vector timeseries with the coarser resolution?

1 次查看(过去 30 天)
Hello all,
I've got two vectors of timeseries and the corresponding datasets.
1. So, I've got time_observed = [2003-01-03 15:30; 2003-01-21 15:20;......;2008-12-18], which is a an text file with 100 values.
2. Also, I've got the corresponding vector (data_observed), which is a vector of 100 values.
****************
3. Then, I've got the timeseries, time_simulated = [1998-01-01 12:00; 1998-01-02 12:00;....;2007-12-29 12:00], which is a text file with 3650 values.
4. Finally, I've got the corresponding data, (data_simulated), which is a vector of 3650 values.
****************
I need to 'interpolate' the (data_simulated) vector to the coarser resolution; so that the (time_simulated) vector together with the (data_simulated) vector would match as close as possible to the (time_observed) vector.
At the end I need to get a new data (say data_new), with the length of the (dates_observed) and (data_observed) (130 x 1)

回答(1 个)

Walter Roberson
Walter Roberson 2015-6-11
Let T_simulated be time_simulated converted to datenumbers, and T_observed be time_observed converted to datenumbers. Then
predicted_data = interp1(T_simulated, data_simulated, T_observed);
and now you can do things like
plot(T_observed, predicted_data - data_observed)
  1 个评论
Christina
Christina 2015-6-11
Hi Walter
Thanks for your reply. Unfortunately, I get the error
'The grid vectors are not strictly monotonic increasing'
********
My code looks like:
%Observed dates
fid_obs = fopen('dates_observed.csv', 'rt');
dates_obs = textscan(fid_obs, '%s');
fclose(fid_obs)
dates_obs_num = datenum(dates_obs{1,1});
%%%%%%%%
%Simulated dates
fid_sim = fopen('dates_simulated.csv', 'rt');
dates_sim = textscan(fid_sim, '%s');
fclose(fid_sim)
dates_sim_num = datenum(dates_sim{1,1});
%%%%%%%%
data_new_sim = interp1(dates_sim_num,data_simulated,dates_obs_num);

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by