Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Griddata: Not enough sample points specified

Subject: Griddata: Not enough sample points specified

From: Sls0039

Date: 29 Oct, 2012 15:26:08

Message: 1 of 2

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?
This line of code also has an error in it: Z = griddata(zpts(:,1),zpts(:,2),zpts(:,3),X,Y);
and I have no clue as to why.
Here is all of the code: (there are notes at the ends of the lines <green matlab text>
function Crinoid(data)
%Crinoid - routine to interpolate 3-D values for a crinoid specimen
% Functionalized for convenience
% Call syntax : Crinoid(data)

%Copy the data so the original is preserved - not really necessary if run
%as a function (because all aviarbles are local
data='BackGS5Data.csv';
centroids=data;
%Find all the points where there is z data
zpts=data(data(:,3)>0,:);
%zpts=data;

%Find the x,y extent of the data
minx=min(centroids(:,1));
maxx=max(centroids(:,1));
miny=min(centroids(:,2));
maxy=max(centroids(:,2));

%Make a mesh using the values with z > 0
[X,Y]=meshgrid(minx:.1:maxx,miny:.1:maxy);
Z = griddata(zpts(:,1),zpts(:,2),zpts(:,3),X,Y); %#ok<GRIDD>
mesh(X,Y,Z)

%Plot the x,y data
hold
plot3(zpts(:,1),zpts(:,2),zpts(:,3),'.')
%Interpolate z-values for all the x,y locations
ZI=interp2(X,Y,Z,centroids(:,1),centroids(:,2));
plot3(centroids(:,1),centroids(:,2),ZI,'.')
axis equal; %You can toggle this off the see exaggerated height
hold off

%Catenate the interpolated z-values to the x,y locations
outmat=horzcat(centroids(:,1),centroids(:,2),ZI);
%Flag any NotANumbers (NANs)and set to zero
outmat(find(isnan(outmat(:,3))),3)=0.0;

%Write the output text file
dlmwrite('BackGS5Data.txt',outmat,'newline','pc');

Subject: Griddata: Not enough sample points specified

From: Roger Stafford

Date: 30 Oct, 2012 04:14:08

Message: 2 of 2

"Sls0039" wrote in message <k6m76g$414$1@newscl01ah.mathworks.com>...
> 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?
> This line of code also has an error in it: Z = griddata(zpts(:,1),zpts(:,2),zpts(:,3),X,Y);
> and I have no clue as to why.
- - - - - - - - -
  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.

  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 X-Y rectangle.

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us