MATLAB: How to create a 3D surface with points of data in MATLAB 6.5 (R13)

3-ddataMATLABmodelpointsshellskinsurface

I have a set of data that are sampled from the outer walls of a spherical object. I would like to create a 3D object that I can rotate and translate.

Best Answer

You can create 3D surface with points of data by using the DELAUNAY3 and TRISURF functions as shown in the example code below:
load data;%You can find the data MAT-file in the resolution documents
%Extract the X, Y and Z coordinates
X=M(:,1);
Y=M(:,2);
Z=M(:,3);
%Generate the surface
T=delaunay3(X,Y,Z);
%Create and apply the colormap
c = zeros(64,3);
for i = 1:64
c(i,1) = .5;%(i+32)/100;
c(i,2) = 0;%i/100;

c(i,3) = 0;%i/100;
end
colormap(c);
%Plot the surface

hObj = trisurf(T,X,Y,Z,'FaceColor','interp','FaceLighting','phong');
shading interp
Please note that if you wish to rotate the object with ROTATE in MATLAB 7.0.1 (R14SP1) or earlier, you cannot use the above code as there is a bug with rotating patches with interpolated shading (see the Related Solution section for more details). However, you can use flat shading with ROTATE instead by using the following commands:
%Plot the surface
hObj = trisurf(T,X,Y,Z,'FaceLighting','phong');
set(hObj,'FaceVertexCData',[1]);
%set(hObj,'edgecolor','none'); % You can turn off the edgecolor as well
set(hObj,'edgecolor',[0.64 0.1 0.1])
rotate(hObj,[1 0 0],180);% Rotate the object on its x-axis by 180 degrees