Irregular time series data interpolation

1 view (last 30 days)
Hi all,
I have a time series data: (date, time, tide height)
11/4/2013 2:49 0.39
11/4/2013 8:59 -0.39
11/4/2013 15:12 0.4
etc.
How to interpolate the data so I can get tide height values with interval of 10 minutes?
Thanks Andi

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 6 Dec 2013
Edited: Andrei Bobrov on 6 Dec 2013
f = fopen('yourdata.txt');
c = textscan(f,'%s %s %f');
fclose(f);
DT = datenum(strcat(c{1:2}),'mm/dd/yyyyHH:MM');
dt = 1/24/6; % (10 minites)/day'
p = ceil(DT(1)/dt);
[y,m,d,h,mm] = datevec(p*dt);
dn = datenum(y,m,d,h,mm+10*(0:floor(DT(end)/dt) - p)');
dv = datevec(dn);
out = [dv(:,1:5),interp1(DT,c{3},dn)];
  3 Comments
Andiyu
Andiyu on 11 Dec 2013
solved the problem
f = fopen('data.txt');
c = textscan(f,'%s %s %f');
fclose(f);
DT = datenum(strcat(c{1:2}),'dd/mm/yyyyHH:MM');
dt = 1/24/6; % (10 minites)/day'
p = ceil(DT(1)/dt);
[y,m,d,h,mm,ss] = datevec(p*dt);
dn = datenum(y,m,d,h,mm+10*(0:floor(DT(end)/dt) - p)',ss);
dv = datevec(dn);
out = [dv(:,1:5),interp1(DT,c{3},dn)];
ceb
ceb on 7 Mar 2015
Hi Andrei and or Andiyu, It's an older thread but if you are still around... I was looking to do basically the same thing as Andiyu except interpolate 1 minute data from 10 minute data. I was able to adjust your above code to get (almost) what I am after but changing the following line: dn = datenum(y,m,d,h,mm+10*(0:floor(DT(end)/dt) - p)',ss); to dn = datenum(y,m,d,h,mm+1*(0:floor(DT(end)/dt) - p)',ss);
BUT the output is only as many rows as the original data - meaning I am still missing interpolated data. Original data is from 5/2/2015 to 26/2/2015 but results only go from 5/2/2015 to 7/2/2015. I am not sure what else in the code needs to be changed... Any suggestions? Thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!