Dennis3r
Dennis3r

Reputation: 31

Filling missing data in a data set

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...

Upvotes: 1

Views: 99

Answers (1)

Santhan Salai
Santhan Salai

Reputation: 3898

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

Upvotes: 1

Related Questions