2

我正在尝试在 Matlab 中创建一系列随机分布的球体,三个将是三个子集。我希望每个子集都有不同的颜色。我正在使用一个结构,因为每个球体也将具有与之相关的不同属性。我尝试使用颜色图和 set(...'FaceColor'..) 但遇到了一些困难。请帮忙。

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);
end 

%%
[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))
end
4

1 回答 1

1

Create a matrix c corresponding to the color of each point on the sphere. Then,

[x y z] = sphere;
surf(x,y,z,c);

More documentation on surf here.

于 2012-11-30T20:15:58.820 回答