How to interpolate vector data sets using interp2()

10 vues (au cours des 30 derniers jours)
Austin McDonald
Austin McDonald le 2 Avr 2024
Réponse apportée : Voss le 2 Avr 2024
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)
Error using griddedInterpolant
Interpolation requires at least two sample points for each grid dimension.

Error in interp2>makegriddedinterp (line 226)
F = griddedInterpolant(varargin{:});

Error in interp2 (line 134)
F = makegriddedinterp(X, Y, V, method,extrap);

Réponse acceptée

Voss
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)
Vq = 216.2827

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by