Change color of different spheres
5 ビュー (過去 30 日間)
古いコメントを表示
I have the following code to plot a sphere
[x y z] = sphere; a=[loc ;radius]; a = transpose(a); surf(x*a(1,4)+a(1,1),y*a(1,4)+a(1,2),z*a(1,4)+a(1,3), 'FaceColor', 'interp') %daspect([1 1 1]) %view(30,10)
colormap(color) shading interp
with loc and radius as variable inputs. I am trying to plot multiple spheres with different colors each. However, when I run this code with multiple spheres using hold on, the only color I get is whatever last color input I put in. How can I edit my code so each sphere has its own color?
loc could be something like [1, 1, 1], radius can be something like 2 and color like [1 1 0] Thanks
0 件のコメント
回答 (2 件)
pfb
2015 年 4 月 20 日
編集済み: pfb
2015 年 4 月 20 日
Where exactly are you specifying the sphere color?
Because it seems to me that in the above command you're not.
You should go (e.g.)
surf(x*a(1,4)+a(1,1),y*a(1,4)+a(1,2),z*a(1,4)+a(1,3), 'FaceColor', [1 0 0]);
You might consider adding a light
light
0 件のコメント
Star Strider
2015 年 4 月 20 日
Set the 'FaceColor' property to the color you want. Borrowing the code from the sphere documentation and tweaking it:
[x,y,z] = sphere;
figure
hs1 = surf(x,y,z);
hold on
hs2 = surf(x+3,y-2,z); % centered at (3,-2,0)
hs3 = surf(x,y+1,z-3); % centered at (0,1,-3)
q1 = get(hs1);
set(hs1, 'FaceColor', [1 0 0])
set(hs2, 'FaceColor', [0 1 0])
set(hs3, 'FaceColor', [0 0 1])
axis equal
You may need to experiment to get the exact result you want.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!