Griddata gives NaN values

33 次查看(过去 30 天)
mehra
mehra 2020-6-21
评论: darova 2020-6-23
Hello
In my code griddata gives NaN values, I checked if my query points are outside the convex hull of the sample data with the following code :
Xv=topologym_vert(:,1)/D;
Yv=topologym_vert(:,2)/D;
Zv=topologym_vert(:,3)/D;
ch=convhull(Xv,Zv)
plot(Xv(ch),Zv(ch),'r',xv,zv,'g')
and it seems everything is ok there,
So I wonder what else I have to change to get rid of NaN values?
the following is my code:
[xv,zv]=meshgrid(linspace((1/3),12,100),linspace(0.14,2.4,50));
aaa =
-0.0434 -0.0122 0.0507 0.2726 0.2433 0.2366 0.2452 -0.0344 -0.0225 0.0504 0.2446 0.2414
0.2426 0.2365 -0.0636 -0.0299 0.1221 0.2021 0.2335 0.2447 0.2399 -0.0342 -0.0002 0.0855
0.1676 0.2263 0.2327 0.2397 0.0827 0.0961 0.1150 0.1465 0.2199 0.2319 0.2346 0.0958
0.1031 0.1428 0.1659 0.2065 0.2332 0.2373 0.0896 0.0767 0.1249 0.1763 0.2160 0.2321
0.2334 0.1084 0.1224 0.1356 0.1621 0.2262 0.2353 0.0656 0.1133 0.1299 0.1539 0.2001
0.2315 0.2340 0.1426 0.1399 0.1321 0.2093 0.2289 0.1369 0.1675 0.1644 0.2151 0.2308
0.1828 0.1668 0.1648 0.1755 0.2038 0.2264 0.2319 0.2012 0.1875 0.2016 0.1872 0.2070
0.2210 0.2334
uvD=griddata(Xv,Zv,aaa,xv,zv);
Xv and Zv are attached.
Thanks.
  2 个评论
John D'Errico
John D'Errico 2020-6-21
You do not provide the actual data, so it is impossible to know if the (xv,zv) points truly fall inside the convex hull of the data. All we have is your claim that the points appear to do so, when looking at a plot that we have not been given.
There are TWO possibilities, neither of which can be ruled out.
  1. One or more of your data points may have a NaN in it.
  2. the numbers you show with 2 significant digits 0.14 and 2.4, for example, are only approximations to the real range of your data.
I see one other inconsistency,
Yv=topologym_vert(:,2)/D;
I note that Yv is never used, yet I wonder if it may have been important.
mehra
mehra 2020-6-21
编辑:mehra 2020-6-21
yes Yv is not necessary here
I attached the actual data for Xv and Zv in my original question
thanks

请先登录,再进行评论。

回答(1 个)

darova
darova 2020-6-22
I think you are using griddata in a wrong way
clc,clear
load Xv.mat
load Zv.mat
load data.txt
xx = linspace(min(Xv),max(Xv),20);
zz = linspace(min(Zv),max(Zv),20);
[xv,zv] = meshgrid(xx,zz); % create 2d mesh
yv = griddata(Xv,Zv,data,xv,zv); % interpolate data
plot3(Xv,Zv,data,'.r')
surface(xv,zv,yv)
axis vis3d
  2 个评论
mehra
mehra 2020-6-22
编辑:mehra 2020-6-22
I cant understand whats wrong with the way I use griddata, I am using it the same as yours but i use the required meshgrid and limits
[xv,zv]=meshgrid(linspace((1/3),12,100),linspace(0.2,2.4,50)); % This is Ok
Xv and Zv are also Ok,
But why the NaN values apear?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by