Filter löschen
Filter löschen

Using surf to represent a function with color.

3 Ansichten (letzte 30 Tage)
John Draper
John Draper am 22 Dez. 2015
Kommentiert: Walter Roberson am 23 Dez. 2015
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?

Antworten (1)

Walter Roberson
Walter Roberson am 22 Dez. 2015
Delete the theta = linspace(0,pi) that you are using to redefine theta.
  2 Kommentare
John Draper
John Draper am 22 Dez. 2015
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 am 23 Dez. 2015
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')

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by