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 3D 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 zvalues 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 zvalues 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');
