MATLAB Answers


Creating spheres In Matlab that change surface color depending on data

Asked by Naqi
on 30 Nov 2012

I am trying to create a series of randomly distributed spheres in Matlab, three will be three sub-sets. I would like each subset to have a different color. I am using a structure because each sphere will also have different properties associated with it. I tried using colormap, and set(...'FaceColor'..) but am having some difficulty. Please Help.

for n = 1:100
    Bslice.cell(n).index = n; 
    Bslice.cell(n).type = 'Tyep1'; % Type2, Type3
     Bslice.cell(n).location = round(rand(1, 3)*10);
[x,y,z] = sphere;
for n = 1:10
    hold on 
    grid on
    surfl(x-Bslice.cell(n).location(1), y-Bslice.cell(n).location(2), z-           Bslice.cell(n).location(3)) 
    shading interp
    % colormap(hot(100))

  1 Comment

FaceColor and an RGB triple should work in theory; could you show an example of how you called it?

0 Answers

Join the 15-year community celebration.

Play games and win prizes!

Learn more
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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!