필터 지우기
필터 지우기

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

조회 수: 5 (최근 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