Is the 3D griddata example correct?
이전 댓글 표시
I'm trying to get my head around griddata so that I can plot an intensity as the colour on a 3D surface (a hemisphere). When I start with the example on the Mathworks website "Interpolate 3-D data set over over a grid in the x-y plane" I get the same error as I do in my own code. The code copied from the Mathworks website is as follows:
rng(0,'twister')
x = 2*rand(5000,1)-1;
y = 2*rand(5000,1)-1;
z = 2*rand(5000,1)-1;
v = x.^2 + y.^2 + z.^2;
d = -0.8:0.05:0.8;
[xq,yq,zq] = meshgrid(d,d,0);
vq = griddata(x,y,z,v,xq,yq,zq);
surf(xq,yq,vq);
set(gca,'XTick',[-1 -0.5 0 0.5 1]);
set(gca,'YTick',[-1 -0.5 0 0.5 1]);
The subsequent error is as follows:
Error using griddata (line 51)
XI and YI must be the same size or vectors of different orientations.
Error in griddatatest (line 11)
vq = griddata(x,y,z,v,xq,yq,zq);
I presume I have copied and pasted it correctly from Mathworks Central?! I thought it would be a good place to start for my own code...
댓글 수: 5
Brady Flinchum
2013년 5월 19일
Did you find a solution to this? It doesn't work for me either.
the cyclist
2013년 5월 19일
That code works for me. I am using version R2013a on a Mac running OS X 10.8.3.
Brady Flinchum
2013년 5월 20일
Well I just tried it with version 7.10.0.499 (R2010a) on my mac OS X and it doesn't work. I wonder if they updated griddata in the newer versions. I will try another computer on campus.
This is really frustrating because the gridddata command seems to be the easiest way to to this. I have tried for about 8 hours now. I am just trying to plot 4 different planes of data. I have come really close using the surfc command but this does not interpolate. I also want to draw contours on each of the planes.
if true
close all
surfc(reshape(x,332,62),reshape(y,332,62),reshape(z,332,62),reshape(c,332,62),'edgecolor','none')
hold on
surfc(reshape(x1,332,74),reshape(y1,332,74),reshape(z1,332,74),reshape(c1,332,74),'edgecolor','none')
hold on
surfc(reshape(x2,332,70),reshape(y2,332,70),reshape(z2,332,70),reshape(c2,332,70),'edgecolor','none')
hold on
surfc(reshape(x3,332,74),reshape(y3,332,74),reshape(z3,332,74),reshape(c3,332,74),'edgecolor','none')
caxis([1 4.667])
colormap(jet)
xlim([2 110])
ylim([-110 0])
zlim([-18 0])
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
end

Eric Sampson
2013년 5월 20일
They did some pretty significant updates to the internals of griddata over the years, I can't remember exactly what release though. I think it does explain what you're seeing; there is likely a way to make in work in R2010 if needed, but the old version isn't as robust as the new one so it would require some fiddling around with the various griddata options.
Brady Flinchum
2013년 5월 21일
Ya I checked it on one of the newer university computers with the 2012 release and it worked fine. After analyzing this script in more detail some it wasn't exactly what I wanted to do anyways.
Thanks for the speedy reply!
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!