Attempting to interpolate with interp2 and getting errors about the sample point vector?
Show older comments
Im trying to interpolate between 4 points in a square (origin to 1 in both x and y direction).
I used [x, y] = meshgrid(0:0.01:1, 0:0.01:1);
x = [0 1 1 0];
y = [0 0 1 1];
and now try to interpolate: interp2(x, y, strains, x, y, 'linear');
my matrix strains has an x and a y component for each of the 4 corners: [x1, y1; x2, y2, x3, y3; x4, y4]
I keep getting errors like: "Interpolation requires at least two sample points for each grid dimension."
what am I missing? It doesnt work if each point only has one strain value either
Accepted Answer
More Answers (1)
Walter Roberson
on 19 Nov 2024
[x, y] = meshgrid(0:0.01:1, 0:0.01:1);
x = [0 1 1 0];
y = [0 0 1 1];
You are overwriting the grids of data produced by meshgrid() with your explicit assignment of vectors to x and y.
interp2(x, y, strains, x, y, 'linear')
This says that at x(J,K), y(J,K) the data is strains(J,K) and asks for linear interpolation at the exact same set of points, x(J,K) y(J,K) . interp2() does not do any kind of smoothing. If you ask for outputs at exactly the same place as your inputs, you are going to get the exact values copied out of strains (to within round-off error.) There is no point in doing interp2() for this situation.
Now, what would make more sense is if you were to use
[x, y] = meshgrid(0:0.01:1, 0:0.01:1);
X = [0 1 1 0];
Y = [0 0 1 1];
interp2(x, y, strains, X, Y, 'linear')
On the other hand, this is just going to reply with strains(1,1), strains(1,end), strains(end,end), strains(end,1)
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!