http://www.mathworks.com/matlabcentral/newsreader/view_thread/324116
MATLAB Central Newsreader  Griddata: Not enough sample points specified
Feed for thread: Griddata: Not enough sample points specified
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Mon, 29 Oct 2012 15:26:08 +0000
Griddata: Not enough sample points specified
http://www.mathworks.com/matlabcentral/newsreader/view_thread/324116#890494
Sls0039
I'm quite new to MatLab and really am only using it for a tiny bit of my thesis. I am trying to interpolate 3D values (x,y,z) to make a 3D model of a fossil. I have a set of code that SHOULD work, but it tells me that the griddata doesn't have enough sample points specified. Does anyone know how to fix this or can anyone tell me where to direct my attention to? <br>
This line of code also has an error in it: Z = griddata(zpts(:,1),zpts(:,2),zpts(:,3),X,Y); <br>
and I have no clue as to why. <br>
Here is all of the code: (there are notes at the ends of the lines <green matlab text> <br>
function Crinoid(data)<br>
%Crinoid  routine to interpolate 3D values for a crinoid specimen<br>
% Functionalized for convenience<br>
% Call syntax : Crinoid(data)<br>
<br>
%Copy the data so the original is preserved  not really necessary if run<br>
%as a function (because all aviarbles are local<br>
data='BackGS5Data.csv';<br>
centroids=data;<br>
%Find all the points where there is z data<br>
zpts=data(data(:,3)>0,:);<br>
%zpts=data;<br>
<br>
%Find the x,y extent of the data<br>
minx=min(centroids(:,1));<br>
maxx=max(centroids(:,1));<br>
miny=min(centroids(:,2));<br>
maxy=max(centroids(:,2));<br>
<br>
%Make a mesh using the values with z > 0<br>
[X,Y]=meshgrid(minx:.1:maxx,miny:.1:maxy);<br>
Z = griddata(zpts(:,1),zpts(:,2),zpts(:,3),X,Y); %#ok<GRIDD><br>
mesh(X,Y,Z)<br>
<br>
%Plot the x,y data<br>
hold<br>
plot3(zpts(:,1),zpts(:,2),zpts(:,3),'.')<br>
%Interpolate zvalues for all the x,y locations<br>
ZI=interp2(X,Y,Z,centroids(:,1),centroids(:,2));<br>
plot3(centroids(:,1),centroids(:,2),ZI,'.')<br>
axis equal; %You can toggle this off the see exaggerated height<br>
hold off<br>
<br>
%Catenate the interpolated zvalues to the x,y locations<br>
outmat=horzcat(centroids(:,1),centroids(:,2),ZI);<br>
%Flag any NotANumbers (NANs)and set to zero<br>
outmat(find(isnan(outmat(:,3))),3)=0.0;<br>
<br>
%Write the output text file<br>
dlmwrite('BackGS5Data.txt',outmat,'newline','pc');

Tue, 30 Oct 2012 04:14:08 +0000
Re: Griddata: Not enough sample points specified
http://www.mathworks.com/matlabcentral/newsreader/view_thread/324116#890541
Roger Stafford
"Sls0039" wrote in message <k6m76g$414$1@newscl01ah.mathworks.com>...<br>
> I have a set of code that SHOULD work, but it tells me that the griddata doesn't have enough sample points specified. Does anyone know how to fix this or can anyone tell me where to direct my attention to? <br>
> This line of code also has an error in it: Z = griddata(zpts(:,1),zpts(:,2),zpts(:,3),X,Y); <br>
> and I have no clue as to why. <br>
        <br>
Very likely 'griddata' is complaining because the area enclosed by your X and Y matrices extends well outside the natural area enclosed by the "crinoid" points given by 'zpts'. It doesn't have enough information to extrapolate throughout that entire area.<br>
<br>
In their manual concerning 'griddata' Mathworks has recommended that 'TriScatteredInterp' be used instead. You might try that with a more realistic area rather than your XY rectangle.<br>
<br>
Roger Stafford