Why is interp2 producing NaN values?
Mostra commenti meno recenti
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)))
Risposta accettata
Più risposte (1)
Mehmed Saad
il 13 Apr 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);
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!