How to interpolate vector data sets using interp2()
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Austin McDonald
am 2 Apr. 2024
Beantwortet: Voss
am 2 Apr. 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)
0 Kommentare
Akzeptierte Antwort
Voss
am 2 Apr. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!