Irregular time series data interpolation

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

 采纳的回答

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 个评论

Hi Andrei,
Thank you for the answer..but I still got error
Error using datenum (line 179) DATENUM failed.
Caused by: Error using datenum (line 165) Incorrect number of arguments
Can you please explain?
Cheers, Andi
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)];
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!

请先登录,再进行评论。

更多回答(0 个)

类别

Community Treasure Hunt

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

Start Hunting!

Translated by