Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Optimize to get rid of loop
Date: Thu, 26 Feb 2009 06:22:02 +0000 (UTC)
Organization: Battelle Energy Alliance (INL)
Lines: 24
Message-ID: <go5cea$f96$1@fred.mathworks.com>
References: <go5am2$g2a$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 1235629322 15654 172.30.248.35 (26 Feb 2009 06:22:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 26 Feb 2009 06:22:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 688530
Xref: news.mathworks.com comp.soft-sys.matlab:520927

Your account of what you are doing is not complete, yet I will make a guess:



bead = round(rand(8,2)*10)
s = size(bead,1);
rg = 0;

for n = 1:s
    for k = n+1:s
        rg = rg + ( bead(k,1) - bead(n,1) )^2 + ( bead(k,2) - bead(n,2) )^2; 
    end
end
rg
%-------------  Method 2 ----------------------%
S = nchoosek(1:size(bead,1),2);
rg2 = sum((bead(S(:,1),1)-bead(S(:,2),1)).^2 +...
          (bead(S(:,1),2)-bead(S(:,2),2)).^2)





J]Bh_bXT#JLhh^hNYN6hhoXoQN.X]hK]RUvJQJVhYKJWQXXPLRU)XN^JJVW