How can I set limits to an interpolation with griddata?

2 views (last 30 days)
Hi, I have a problem with a Matlab code which I created to make an interpolation for a measurement series inside a mesh. The problem is that the measurements range from 0 to 1 and I need to interpolate between these two values but, when I apply griddata I have values below 0 and above 1. How can I correct this? This is the code I have created:
file='Muro_1e.xlsx';
x=xlsread(char(file),1,'b1:b20');
y=xlsread(char(file),1,'c1:c20');
z=xlsread(char(file),1,'h1:h20');
px=x(1:20);
py=y(1:20);
n=200; %number of subdivisions for plotting purposes
[xi,yi]=meshgrid(linspace(min(x),max(x),n),linspace(min(y),max(y),n));
zi=griddata(x,y,z,xi,yi,'cubic');

Accepted Answer

John D'Errico
John D'Errico on 14 Jun 2018
Edited: John D'Errico on 14 Jun 2018
You cannot set limits when using griddata, AND the 'cubic' option. It will happily interpolate smoothly as it will. But that may possibly result in a fit that exceeds the limits of your data.
If you insist on an interpolation that stays within the limits of your data, then linear or nearest neighbor interpolation will do so, but they will not be smooth interpolants.
There is one other option in griddata that will at least try to produce a smoother interpolant than the linear interpolant. That is the 'natural' interpolant. And I believe it will stay within the boundaries of your data. So if your data lives in [0,1], then so should the 'natural' interpolant in griddata. (I'd need to read the reference provided in the docs for scatteredInterpolant to be absolutely positive of this statement however.)

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!