How to interpolate vector data sets using interp2()

9 次查看(过去 30 天)
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);

采纳的回答

Voss
Voss 2024-4-2
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by