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:
3D plotting

Subject: 3D plotting

From: John Wise

Date: 5 Apr, 2012 14:29:30

Message: 1 of 3

Hi,
I have a shape represented by x,y,z and I want to plot the heat h on this surface, I tried surf, contourf but they all work with 2D. help please

Subject: 3D plotting

From: John Wise

Date: 5 Apr, 2012 16:54:18

Message: 2 of 3

"John Wise" wrote in message <jlka8a$lrq$1@newscl01ah.mathworks.com>...
> Hi,
> I have a shape represented by x,y,z and I want to plot the heat h on this surface, I tried surf, contourf but they all work with 2D. help please
I tried to use scatter3 but it gave me this messege (X, Y and Z must be vectors of the same length) I checked they all have the same size
any help please?

Subject: 3D plotting

From: ScottB

Date: 5 Apr, 2012 22:35:35

Message: 3 of 3

"John Wise" wrote in message <jlka8a$lrq$1@newscl01ah.mathworks.com>...
> Hi,
> I have a shape represented by x,y,z and I want to plot the heat h on this surface, I tried surf, contourf but they all work with 2D. help please

John,

You have a 3D shape in terms of x,y,z and you have heat h also in terms of x,y,z. You can use of the form of the surf command described in the documentation as :

"surf(X,Y,Z,C) creates a shaded surface, with color defined by C. MATLAB performs a linear transformation on this data to obtain colors from the current colormap."

A simple of example of a sphere in x,y,z with some random coloring applied:

% create some image data
[X Y Z] = sphere(25);
sz = size(Z);
C = rand(sz(1),sz(2),3);

% stitch data to wrap color around sphere
C(:,end,:) = C(:,1,:);

% render an image
figure('color',[0 0 0]);
sp = surf(X,Y,Z,C,'FaceColor','interp',...
    'FaceLighting','phong',...
    'BackFaceLighting','lit');
material shiny
axis off vis3d
cl = camlight('right');
camzoom(1.5)
set(sp,'EdgeColor','none');
set(sp,'EdgeAlpha',1);
drawnow

hope that helps,
ScottB

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