Filling missing data in a data set

二次信任 提交于 2019-12-11 11:18:21

问题


I have a data set like the following:

x= [1, 4, 10]
y= [10, 20, 30]

(x and y are value pairs, i.e. (1,10), (4,20), (10,30))

I would like to fill the x values gaps and get linear interpolated values for y. The linear interpolation should be done between each value pair, i.e. between (1,10) and (4,20) and then again between (4,20) and (10,30).

x= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y= [10,?, ?, 20, ?, ?, ?, ?, ?, 30]

How can I solve this with MATLAB? Regards, Dennis

P.S. My original data set has over 300 value pairs...


回答1:


Using interp1

Code:

x= [1, 4, 10];
y= [10, 20, 30];
xi = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
yi = interp1(x,y,xi);

Results:

>> yi

yi =

  10    13.333   16.667    20    21.667    23.333    25    26.667   28.333     30

Graphical Output using plot(xi,yi,'-*')



来源:https://stackoverflow.com/questions/29591624/filling-missing-data-in-a-data-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!