# meshgrid and griddata usage and NaN results for griddata

7 visualizzazioni (ultimi 30 giorni)
Arundhatee Talukdar il 11 Nov 2011
I am trying to use meshgrid and griddata for plotting vv values over x and y Where
vv= 10000*1 matrix where I stored the (z)values for my points in the plot
and my code is
[X,Y]= meshgrid(1:100, 1:100);
x = rand(10000,1); y = rand(10000,1);
ZI = griddata(x,y,vv,X,Y);
hold on
imshow(ZI, jet);
hold on
I am getting NaN for my ZI values. Why so?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

Seth DeLand il 11 Nov 2011
The GRIDDATA function is trying to use the data in x,y,vv to fit a surface and then interpolate this surface at the points specified in X and Y.
The problem here is that x and y were created with RAND, so they are on the range 0<x<1 and 0<y<1. The points specified in X and Y are on the range 1<X<100 and 1<Y<100. So the range over which we are trying to interpolate has no defined values from the range that the surface was calculated.
A quick way to get some reasonable results would be to modify line 2 to be:
x = 100*rand(10000,1); y = 100*rand(10000,1);
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Arundhatee Talukdar il 13 Nov 2011
Thank you so much. I tried this.
x = 101*rand(10000,1); y = 101*rand(10000,1);
Every element now has a value, but still element (100,1) still showing as NaN. can you please provide me some help here!

Accedi per commentare.

### Categorie

Scopri di più su Surface and Mesh Plots in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by