How to interpolate arrays for smoothening?
165 views (last 30 days)
I'd like to interpolate an array of x-values to apply a spine function to it later (I'd like to smoothen my dataset). However, the x-array is a discontinuous vector, so the general explanation how to interpolate with interp1 does not work for my data. This is the array:
14.1 13.7 12.8 11 9.22 6.18 5.57 5 4.27 3.42 2.57
Does any of you have an idea how I could interpolate this array? Or maybe other ideas how to smoothen it, if not?
Andrew Reibold on 26 Aug 2014
Edited: Andrew Reibold on 26 Aug 2014
To interpolate an array, you need the following
X: An array of data, lets call it your independant data.
Y: An array of data corresponding to X. For each value of X there is a value for Y.
X_interpolated: An array of data of NEW X points at positions you want Y interpolated at.
X = [1 2 3 4 5 6 7]
Y = [10 11.5 14 15 16.5 18 20]
X_interpolated = [1:.5:7]
Y_interpolated = interp1(X,Y,X_interpolated)
Now if you plot
you will find that points have been interpolated to fill in the gaps of the initial data. Specifically, these points are located at whatever you chose for X_interpolated
If you want to make it curvy or smooth after that, if appropriate, you could use 'smooth' to take a moving line average of the data like this
Y_smooth = smooth(Y_interpolated)
Otherwise I would suggest trying to use something like polyfit for your function... if its a function.