How to interpolate arrays for smoothening?
126 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
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?
Réponses (1)
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.
Voir également
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!