griddedInterpolant error "Interpolation requires at least two sample points for each grid dimension."
175 次查看(过去 30 天)
显示 更早的评论
I'm systematically getting this error trying to use griddedInterpolant. Here's a simple example:
bp1 = [0:1:10];
bp2 = [5:0.5:10];
bp3 = [2:0.1:3];
tv = bp1.*bp3+bp2.^2
f=griddedInterpolant(bp1,bp2,bp3,tv)
But I get the error:
Error using griddedInterpolant
Interpolation requires at least two sample points for each grid dimension.
What have I missed?
0 个评论
回答(2 个)
Voss
2023-12-1
The points (bp1, bp2, bp3) in 3d space do not form a grid. They are equally-spaced points along a line segment from (0,5,2) to (10,10,3).
You can use ndgrid to construct a set of points that form a grid from your bp1, bp2, bp3 vectors.
bp1 = 0:1:10;
bp2 = 5:0.5:10;
bp3 = 2:0.1:3;
% tv = bp1.*bp3+bp2.^2;
[BP1,BP2,BP3] = ndgrid(bp1,bp2,bp3);
TV = BP1.*BP3+BP2.^2;
f=griddedInterpolant(BP1,BP2,BP3,TV)
5 个评论
Stephen23
2023-12-3
Either call RESHAPE on each column of data.
Or simply call SCATTEREDINTERPOLANT and let it do the work for you.
Star Strider
2023-12-3
The interpn function could be an option. You will need to experiment with the ndgrid function to determine how best to reshape the first 5 columns of your data to conform to it (if they indeed need reshaping — they may not) and then do the interpolation. I am not certain how easy it would be to make sense of the results, much less plot them, since everything in this universe is limited to 3 spatial dimensions and time, last I heard.
If you only want to interpolate specific points or ranges of points within the limits of the original vectors (so not extrapolating), interpn could do what you want.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!