关于Matlab:interp1中的样条插值而不填充nan值

Spline interpolation in interp1 without filling nan values in

我每5分钟有潮汐观测,我想将其插值到1分钟间隔内。

我尝试使用Python进行此操作,但是这花费了太多时间,因此我开始使用MATLAB。 问题在于,样条方法填充了NaN值。

下图说明了该问题,我想在不填充NaN值的情况下进行样条插值。 我怎样才能使interp1函数这样做呢?

the image explain it

1
2
3
4
5
6
file='NANTES_5min_nan.txt'
[date, hauteur] = lecture_hfs(file);
vect=[date(1):1/24/60:date(end)];
h_interp=interp1(date,hauteur,vect,'spline');

h_interp_lin=interp1(date,hauteur,vect,'linear');

第二个数字来自Python插值。 结果不错,但不幸的是,它只有1个月的数据。 当我想将其应用于整个数据(17年)时,执行永无止境,这是python图形的链接


可以将hauteur中与NaN值接近的vect值替换为NaN,而不是直接将vect用作查询点。 这可以通过使用另一个(线性)插值来完成:

1
2
3
temp = date; % copy of the original dates
temp(isnan(hauteur))=NaN; % set the values which are NaN in hauteur to NaN
h_interp = interp1(date,hauteur,interp1(date,temp,vect),'spline'); % the inner interpolation results in vect with NaNs where appropriate

有点混乱,可能会有更优雅的方法,但是我对通过嵌套另一个插值来解决此问题的可能性感到着迷。