Attempting to interpolate with interp2 and getting errors about the sample point vector?
显示 更早的评论
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
采纳的回答
更多回答(1 个)
Walter Roberson
2024-11-19
[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)
类别
在 帮助中心 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!