Reputation: 89
I would like to show several spheres in my 3D spaces, each with a different center location and radius. So I followed the tutorial by Matlab and I get the following result. The only problem is that I might have hundreds of spheres to plot so it won't be possible to write down hundreds of lines. Is there a way to use the surf() function with a matrix input? Maybe surf(x,y,z) with x,y and z matrix? Thanks!
hold on;
[x,y,z] = sphere;
r = 50;
s1 = surf(x*r,y*r,z*r,'FaceAlpha',0.1);
s2 = surf((x+3)*r,(y-2)*r,z*r,'FaceAlpha',0.1); % centered at (3,-2,0)
s3 = surf(x*r,(y+1)*r,(z-3)*r,'FaceAlpha',0.1); % centered at (0,1,-3)
s1.EdgeColor = 'none';
s2.EdgeColor = 'none';
s3.EdgeColor = 'none';
Upvotes: 0
Views: 75
Reputation: 35525
Write it in generic form.... You are almost there:
s = surf((x-cx)*r,(y-cy)*r,(z-cz)*r,'FaceAlpha',0.1);
Now just change cx,cy,cz
with loops
Upvotes: 1