Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: avoiding loops to built a z matrix of the most efficient form
Date: Wed, 25 Mar 2009 21:10:02 +0000 (UTC)
Organization: Battelle Energy Alliance (INL)
Lines: 13
Message-ID: <gqe6ja$4fg$1@fred.mathworks.com>
References: <gqdj93$qa4$1@fred.mathworks.com> <gqdn0i$a5r$1@fred.mathworks.com> <gqdr01$jp4$1@fred.mathworks.com> <gqduat$hug$1@fred.mathworks.com> <gqdvgd$bvg$1@fred.mathworks.com> <gqe1nl$cra$1@fred.mathworks.com> <gqe4fp$1ml$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1238015402 4592 172.30.248.35 (25 Mar 2009 21:10:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 25 Mar 2009 21:10:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 688530
Xref: news.mathworks.com comp.soft-sys.matlab:527755

Just to show that the old For loop isn't as uncompetitive as it seems, try this out for giggles:


tic
z = zeros(1,nrv);
r = ones(nrp,1);
for jj = 1:nrv
    tmp = v2(jj,:);
    tmp2 = v1 - tmp(r,:);  
    tmp3 = tmp2*inversa;
    z(jj) = sum(tmp3(:,1).*tmp2(:,1) + tmp3(:,2).*tmp2(:,2));
end
toc