Filling missing data in a data set

2019-08-12 18:16发布

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条回答
Juvenile、少年°
2楼-- · 2019-08-12 18:50

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,'-*')

enter image description here

查看更多
登录 后发表回答