How to interpolate arrays for smoothening?

126 vues (au cours des 30 derniers jours)
Ellen
Ellen le 26 Août 2014
Commenté : Ellen le 26 Août 2014
Hi all,
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?
Thanks!
  1 commentaire
Adam
Adam le 26 Août 2014
Do you not have a sampling vector to go with that? i.e. the values at which those results were calculated. If you know where your discontinuities are can you not just use interp1 piece-wise between discontinuities?

Connectez-vous pour commenter.

Réponses (1)

Andrew Reibold
Andrew Reibold le 26 Août 2014
Modifié(e) : Andrew Reibold le 26 Août 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.
Example:
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
plot(X_interpolated,Y_interpolated)
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)
plot(X_interpolated, Y_smooth)
Otherwise I would suggest trying to use something like polyfit for your function... if its a function.
  1 commentaire
Ellen
Ellen le 26 Août 2014
Thanks Andrew for your response. The problem with my data is that it is not really a function, but a set of scatterpoints which do not relate. I've checked a lot, including your suggestion for polyfit, but all of this does not work for my set of data. Thanks anyway though!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by