六重for循环如何优化? 。

6 views (last 30 days)
ginaha
ginaha on 23 Nov 2022
for ix=1:N+1
x=-1000+(ix-1)*2000/N;
for iy=1:N+1
y=-1000+(iy-1)*2000/N;
Lx(ix,iy)=x;
Ly(ix,iy)=y;
Exx(ix,iy)=0;
Exy(ix,iy)=0;
iip=0;
iiq=0;
for p= -(N-1)/2:(N-1)/2
iip=iip+1;
for q= -(N-1)/2:(N-1)/2
if sqrt(p^2+q^2)>(N-1)/2
continue;
end
iiq=iiq+1;
sitao=asin(2*NA*sqrt(p^2+q^2)/(N-1));
fano=atan2(q,p);
Eopqx(iip,iiq)=0;
Eopqy(iip,iiq)=0;
for m=-(N-1)/2: (N-1)/2
for n=-(N-1)/2: (N-1)/2
if sqrt(m^2+n^2)>(N-1)/2
continue;
end
sitai=asin (2*NA*sqrt(m^2+n^2)/(N-1));
fani=atan2(n,m);
。。。。。。。。。。。。。。。运行速度超级慢,20个数要2个多小时。

Answers (1)

埃博拉酱
埃博拉酱 on 23 Nov 2024 at 1:21
你的for循环都没有end,显然代码都没贴完整,你让我们怎么帮你优化

Categories

Find more on Licensing on Cloud Platforms in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!