matlab中的线性插值使用2个数组

时间:2017-04-12 09:27:35

标签: matlab interpolation linear spline

我有两个独立的数组,包含两个变量,t& T.我需要使用t和T之间的关系插入一组新的T值。

for k=1:length(t)
[t, index] = unique(t); 
tr_T = interp1(t,T(index),'linear'); %linear interpolation to find new T given t
end 

但是,在插入并导出tr_T值后,原始T曲线的形状不会保留。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

对于插值,您需要3个变量(数组):

  1. 给出采样点
  2. 给出样本值
  3. 所需的采样点
  4. 所以你错过了另一个变量(数组)。我的猜测(由于他们的名字),tT是给定的和所需的采样点,你错过了样本值。如果您有给定的样本值,则插值很容易完成:

    t = [0 sort(rand(1,5)) 1]; % given sampling points
    v = rand(1,7); % given sample values
    T = [0 sort(rand(1,100)) 1]; % desired sampling points
    V = interp1(t,v,T,'linear'); % desired (interpolated) sample values
    % plot
    plot(t,v,'ob');
    hold on
    plot(T,V,'r');
    legend('given data','interpolated data');
    

    enter image description here