Why is interp2 producing NaN values?
Mostrar comentarios más antiguos
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)))
Respuesta aceptada
Más respuestas (1)
Mehmed Saad
el 13 de Abr. de 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);
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!