Using surf to represent a function with color.

1 次查看(过去 30 天)
Hi everyone, I would like to represent the magnitude of a function on a surface (hemisphere) using a color map. Here is my current attempt
r=22; %radius of sphere
phi=linspace(0,pi,30);
theta=linspace(0,pi,40);
[phi,theta]=meshgrid(phi,theta); %meshgrid of sphere
x=r*sin(phi).*cos(theta);
y=r*sin(phi).*sin(theta);
z=r*cos(phi);
mesh(x,y,z)
hold on
theta = linspace(0,pi)
R=1/22 % R=Rs/r (constant)
Bo=21000 %constants
Bmag = Bo*((R).^3).*((1+3*(sin(theta)).^2)).^0.5 %magnetic field function
surf(x,y,z,Bmag)
I then get the error message
Warning: Error creating or updating Surface
Error in value of property CData
Array is wrong shape or size
Does anyone have any idea how I could represent this?

回答(1 个)

Walter Roberson
Walter Roberson 2015-12-22
Delete the theta = linspace(0,pi) that you are using to redefine theta.
  2 个评论
John Draper
John Draper 2015-12-22
Thanks, that gives me a figure. But the hemisphere is all one color now. Is there any way to plot it such that you can see the variation in Bmag across the surface of the hemisphere?
Walter Roberson
Walter Roberson 2015-12-23
Remove the mesh()
The default for mesh is to color by z, so your color values for that range the same as your z, -22 to +22. Then when you surf() with Bmag as the color values (about 1.97 to twice that), MATLAB still has to use a color interpolation range large enough to include the now-hidden mesh, but only a narrow range of values are present in the visible image so they map to a narrow range of visible colors.
By default surf() draws edges, and so outlines the mesh anyhow. You can turn off those edges with
surf(x, y, z, Bmag, 'edgecolor', 'none')

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by