Path: news.mathworks.com!not-for-mail
From: "Zsolt " <zlpst@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: problem vectorizing
Date: Fri, 28 Nov 2008 23:30:23 +0000 (UTC)
Organization: University of Pittsburgh
Lines: 13
Message-ID: <ggpuuf$scq$1@fred.mathworks.com>
Reply-To: "Zsolt " <zlpst@yahoo.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1227915023 29082 172.30.248.38 (28 Nov 2008 23:30:23 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 28 Nov 2008 23:30:23 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 560311
Xref: news.mathworks.com comp.soft-sys.matlab:503725


I would like to vectorize the double for loop below, can't find matlab matrix operator to proceed, can anyone help?  Note, current implementation performs the correct operation, it just takes way to long for data size I need to calculate for

X = linspace(-a/2,a/2,length(Gpp));
[X Y] = meshgrid(X);
r = sqrt((X).^2+(Y).^2);
tic
ep = zeros(size(Egp));

for m=1:length(Gpp)
    for n=1:length(Gpp)
        ep = ep + Egp(m,n)*exp(i*Gpp(m,n).*r);
    end
end