How do I create a 3D surface with points of data in MATLAB 6.5 (R13)?

13 views (last 30 days)
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.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
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
  1 Comment
Sriram Narayanan
Sriram Narayanan on 21 Apr 2014
Edited: MathWorks Support Team on 3 Aug 2020
Starting MATLAB 7.9 (R2009b), it is recommended to use "DelaunayTri" function for 3-D surface plot.
The "DelaunayTri" function was removed in R2012b. Therefore, starting MATLAB 8.1 (R2013a), it is recommended to use the "delaunaytriangulation" function instead.
Please refer to the following documentation link that gives an example on how to generate and visualize a 3-D surface.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!