Info
此问题已关闭。 请重新打开它进行编辑或回答。
Simplification of two for loops
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I would like to simplify the two for loop to accelerate my calculation time
Maybe, you have an idea how can I do it. My code draw inside the Matrix M(N,N) the circles with following function
M(i,j)=(1-sin((pi*rad)/(2*radius1)))*exp(w*rad).
So, I have:
M=zeros(N,N);
for i=1:N
for j=1:N
if (i-i1)^2+(j-j1)^2 < radius1^2
radius = sqrt((i-i1)^2+(j-j1)^2);
M(i,j)=(1-sin((pi*radius)/(2*radius1)))*exp(w*radius);
end
end
end
Thank you in advance for any better suggestions!!!
Best regards,
0 个评论
回答(1 个)
Bruno Luong
2020-11-12
i = (1:N)';
j = 1:N;
radius = sqrt((i-i1).^2+(j-j1).^2);
M = (1-sin((pi*radius)/(2*radius1))).*exp(w*radius);
M(radius>=radius1) = 0;
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!