How can I use 'interp3' with irregularly spaced sample points?
12 views (last 30 days)
Show older comments
MathWorks Support Team
on 13 May 2021
Answered: MathWorks Support Team
on 26 Jul 2021
I have a set of scattered 3D sample points expressed as vectors "xs", "ys", and "zs". Each sample point has a measured output in the vector 'vs'. I want to interpolate a set of scattered 3D query points expressed as vectors "xq", "yq", and "zq", while using "xs", "ys", and "zs" as the sample points.
When I try to do this using "interp3", I receive an error related to "griddedInterpolant":
>> vq = interp3(xs, ys, zs, vs, xq, yq, zq);
Error using griddedInterpolant
Interpolation requires at least two sample points for each grid dimension.
How can I get rid of this error and make "interp3" work when the sample points are irregularly spaced? Does MATLAB support this kind of interpolation?
Accepted Answer
MathWorks Support Team
on 13 May 2021
In this case, "interp3" would not be the best option. Under the hood, "interp3" is using a "griddedInterpolant" object to perform the interpolation, which requires sample points to be organized in a grid format.
Instead, please use the "griddata" command. Instead of using a "griddedInterpolant" object, it uses a "scatteredInterpolant" object that accommodates the irregular spacing between your sample points.
You can read the documentation for these components at the following links:
"griddedInterpolant": https://www.mathworks.com/help/matlab/ref/griddedinterpolant.html
"scatteredInterpolant": https://www.mathworks.com/help/matlab/ref/scatteredinterpolant.html
Under the "Input Arguments" section for "griddata", you can see that the X, Y, and Z sample points can be irregularly spaced and do not have to be monotonic. Likewise, the X, Y, and Z query points can remain irregularly spaced as well. This means that you won't have to alter your data at all in order to perform the interpolation with "griddata". Using your variable names as an example, the command would look like this:
>> vq = griddata(xs, ys, zs, vs, xq, yq, zq);
Please be aware that the query points should be located within the convex hull of the sample points. Any query values outside of those bounds will return NaN values.
0 Comments
More Answers (0)
See Also
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!