필터 지우기
필터 지우기

How to plot color ball use matlab?

조회 수: 3 (최근 30일)
z cy
z cy 2021년 10월 20일
댓글: Star Strider 2021년 10월 22일
What I want know how to plot color ball use matlab? And we need to get the [x,y,z] for each color point. Thanks! The white color can be ignored.

채택된 답변

Star Strider
Star Strider 2021년 10월 20일
This is an interesting problem!
This should get you started —
Facets = 40;
numPatches = fix(Facets/5);
[X,Y,Z] = sphere(Facets-1);
figure
hs = surf(X, Y, Z, 'EdgeColor','none');
colormap(turbo(fix(Facets/3)))
hold on
idxk = 1:fix(Facets/numPatches);
for k = 1:numPatches
idx = idxk + numel(idxk)*(k-1);
hs.CData(:,idx) = k-fix(Facets/2);
end
hold off
grid on
axis('equal')
view(50,30)
rotate(hs, [0.5 1 1],45)
NOTE — The surface patches are defined by the CData colormap colors that go from -1 to +1 so whatever the desired colormap is (I chose turbo that was introduced in R2021a) will automatically map to those values. (After a false start using patch, this turned out to be reasonably straightforward.) The loop works by selecting the columns defined by ‘idx’ and then colouring them according to the value of the colormap at that point. The rotate call is optional, and simply inclines the sphere object so that more of its patches are visible.
Experiment to get different results.
.
  댓글 수: 2
z cy
z cy 2021년 10월 22일
Thanks for your answer!!!
Star Strider
Star Strider 2021년 10월 22일
As always, my pleasure!
Solving this problem was fun!
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by