Why is interp2 producing NaN values?
Afficher commentaires plus anciens
It seems that interp2 produces NaN values on smooth, well-behaved functions. What am I doing wrong? For sure I am making a silly mistake.
Example code:
% define a constant value matrix of 500x500
x = 1:500;
y = 1:500;
[X,Y] = meshgrid(x,y);
f = ones(size(X));
% produce random locations to interpolate f at between 0 and 500
xi = 0 + (500 - 0).*rand(1000,1);
yi = 0 + (500 - 0).*rand(1000,1);
% run interp2
f_interp = interp2(X,Y,f,xi,yi);
% this value should be zero, but I am getting something like 5
sum(sum(isnan(f_interp)))
Réponse acceptée
Plus de réponses (1)
Mehmed Saad
le 13 Avr 2020
I think it is because you are touching boundaries.
Try values below
xi = 1 + (500 - 1).*rand(1000,1);
yi = 1 + (500 - 1).*rand(1000,1);
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!