How to interpolate vector data sets using interp2()

9 ビュー (過去 30 日間)
Austin McDonald
Austin McDonald 2024 年 4 月 2 日
回答済み: Voss 2024 年 4 月 2 日
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 Center および File ExchangeInterpolation についてさらに検索

タグ

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by