How to interpolate vector data sets using interp2()
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to use the interp2() function to interpolate a data point from a set of three vectors.
Vectors x, y, and z are all 10x1 and contain doubles. The data in vector z is assumed to correlate with a function of the data in vectors x and y, such that z = f(x, y).
How do I set up the interp2() to interpolate a value of z using any Xq and Yq that lie within the ranges of the x and y data sets?
I'm using the following code, which produces the error "Interpolation requires at least two sample points for each grid dimension."
x = [800; 900; 1000; 1100; 1200; 1300; 1400; 1500; 1600; 1700];
y = [30; 60; 90; 120; 150; 30; 60; 90; 120; 150];
z = [400; 330; 380; 240; 220; 380; 350; 270; 230; 215];
[X, Y] = meshgrid(x, y);
V = z;
Vq = interp2(X, Y, V, 1105, 130)
0 commentaires
Réponse acceptée
Voss
le 2 Avr 2024
You can't use interp2 with those vectors because they don't define a grid. You can use scatteredInterpolant instead.
x = [800; 900; 1000; 1100; 1200; 1300; 1400; 1500; 1600; 1700];
y = [30; 60; 90; 120; 150; 30; 60; 90; 120; 150];
z = [400; 330; 380; 240; 220; 380; 350; 270; 230; 215];
I = scatteredInterpolant(x,y,z);
Vq = I(1105, 130)
0 commentaires
Plus de réponses (0)
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!