matlab程序优化figure[x,y,z] = sphere;a=surf(x,y,z);% sphere centered at originhold onfor i=1:32for j=1:32a(i,j)=surf(x+2*j,y,z+2*i,c); % sphere centered at (3,-2,0)set(a(i,j),'EdgeColor','g','FaceColor','g')endendwhitebg('w')daspect([1 1 1])这
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/06 13:15:22
![matlab程序优化figure[x,y,z] = sphere;a=surf(x,y,z);% sphere centered at originhold onfor i=1:32for j=1:32a(i,j)=surf(x+2*j,y,z+2*i,c); % sphere centered at (3,-2,0)set(a(i,j),'EdgeColor','g','FaceColor','g')endendwhitebg('w')daspect([1 1 1])这](/uploads/image/z/1340352-0-2.jpg?t=matlab%E7%A8%8B%E5%BA%8F%E4%BC%98%E5%8C%96figure%5Bx%2Cy%2Cz%5D+%3D+sphere%3Ba%3Dsurf%28x%2Cy%2Cz%29%3B%25+sphere+centered+at+originhold+onfor+i%3D1%3A32for+j%3D1%3A32a%28i%2Cj%29%3Dsurf%28x%2B2%2Aj%2Cy%2Cz%2B2%2Ai%2Cc%29%3B+%25+sphere+centered+at+%283%2C-2%2C0%29set%28a%28i%2Cj%29%2C%27EdgeColor%27%2C%27g%27%2C%27FaceColor%27%2C%27g%27%29endendwhitebg%28%27w%27%29daspect%28%5B1+1+1%5D%29%E8%BF%99)
matlab程序优化figure[x,y,z] = sphere;a=surf(x,y,z);% sphere centered at originhold onfor i=1:32for j=1:32a(i,j)=surf(x+2*j,y,z+2*i,c); % sphere centered at (3,-2,0)set(a(i,j),'EdgeColor','g','FaceColor','g')endendwhitebg('w')daspect([1 1 1])这
matlab程序优化
figure
[x,y,z] = sphere;
a=surf(x,y,z);% sphere centered at origin
hold on
for i=1:32
for j=1:32
a(i,j)=surf(x+2*j,y,z+2*i,c);
% sphere centered at (3,-2,0)
set(a(i,j),'EdgeColor','g','FaceColor','g')
end
end
whitebg('w')
daspect([1 1 1])
这个是用来在一个面上画密密麻麻的球体,但是速度过慢了,希望有大神来优化一下这个程序
matlab程序优化figure[x,y,z] = sphere;a=surf(x,y,z);% sphere centered at originhold onfor i=1:32for j=1:32a(i,j)=surf(x+2*j,y,z+2*i,c); % sphere centered at (3,-2,0)set(a(i,j),'EdgeColor','g','FaceColor','g')endendwhitebg('w')daspect([1 1 1])这
把 for 去掉.c++里面 for 运算 非常快捷.但是 matlab里面 for的运算速度会非常慢.你这里还两重for.