matlab中带指数优化的For循环

matlab中带指数优化的For循环,matlab,for-loop,optimization,vectorization,Matlab,For Loop,Optimization,Vectorization,我在计算平面天线阵列的方向图,问题是计算方向图需要10秒,在我的算法中我需要计算很多次。大部分时间用于计算for循环。请告诉我如何减少for循环的执行时间,或者用其他解决方案替换它。提前谢谢 clc; close all; clear all; Nx=32; Ny=32; betta_n = zeros(Nx,Ny); lambda=1; dx = [1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1

我在计算平面天线阵列的方向图,问题是计算方向图需要10秒,在我的算法中我需要计算很多次。大部分时间用于计算for循环。请告诉我如何减少for循环的执行时间,或者用其他解决方案替换它。提前谢谢

clc; close all; clear all;
Nx=32; Ny=32;
betta_n = zeros(Nx,Ny); lambda=1;
dx = [1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 ];
dy = [1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 ];
a_n = ones(Nx, Ny);
dtetta = 0.01;
dphi = 0.01;
tetta0 = -pi/2:dtetta:pi/2;
phi0 = dphi:dphi:2*pi;
[phi, tetta] = meshgrid(phi0,tetta0);
j = sqrt(-1);
amp_phase=a_n.*(cos(betta_n)+j*sin(betta_n));
sinU=sin(tetta).*cos(phi);
sinV=sin(tetta).*sin(phi);
%     AF_Field = 0;
AF_Field = zeros(length(tetta0),length(phi0));
tic
for n=1:Nx-1
    for m=1:Ny-1
        AF_Field = amp_phase(n,m)*exp(j*2*pi*(n-1)/lambda*dx(n)*(sinU)).*exp(j*2*pi*(m-1)/lambda*dy(m)*(sinV)) + AF_Field;  
    end
end
toc

查找表在这里可能会有所帮助…还可以使j*2*pi成为常量,并在循环之前计算。。。SIN和COS计算的查找表会有很大的不同感谢您的帮助,请您详细说明查找表,sinU和sinV是315x628矩阵,如何在循环中使用LUT而不是它们?仅在循环中,如果SIN或COS是在循环内(或在循环内的函数中)计算的,这些可能非常缓慢。315*628是一个小型缓存,但可能不是所需的缓存(查找)。amp_相位是否计算循环中的sin和cos值?考虑预校准所有的SINS和COS值,并将它们存储在数组中,并使用循环内的数组值。