Using surf to represent a function with color.

조회 수: 1 (최근 30일)
John Draper
John Draper 2015년 12월 22일
댓글: Walter Roberson 2015년 12월 23일
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