首页 文章

修改了缺失数据的线性插值

提问于
浏览
0

想象一组具有给定x值(作为列向量)的数据和在矩阵中组合的几个y值(列向量的行向量) . 矩阵中的某些值不可用:

%% Create the test data
N = 1e2; % Number of x-values

x = 2*sort(rand(N, 1))-1;
Y = [x.^2, x.^3, x.^4, x.^5, x.^6]; % Example values
Y(50:80, 4) = NaN(31, 1); % Some values are not avaiable

现在我有一个用于插值的新x值的列向量 .

K = 1e2; % Number of interplolation values
x_i = rand(K, 1);

我的目标是找到一种快速方法来插入给定x_i值的所有y值 . 如果y值中有NaN值,我想使用缺失数据之前的y值 . 在示例中,这将是 Y(49, :) 中的数据 .

如果我使用 interp1 ,我得到NaN值,并且对于大 xx_i 执行速度很慢:

starttime = cputime;
Y_i1 = interp1(x, Y, x_i);
executiontime1 = cputime - starttime

另一种选择是 interp1q ,大约快两倍 .

What is a very fast way which allows my modifications?

可能的想法:

  • Y_i1 进行后处理以消除 NaN -值 .

  • 使用循环和 find 命令的组合始终使用邻居而不进行插值 .

1 回答

  • 1

    使用带有样条插值的 interp1spline )会忽略NaN .

相关问题