Info
This question is closed. Reopen it to edit or answer.
Simplification of two for loops
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Bruno Luong
on 12 Nov 2020
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 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!