Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: trying to avoid using a for loop
Date: Sat, 25 Oct 2008 21:48:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 14
Message-ID: <ge046i$mmi$1@fred.mathworks.com>
References: <gdvpsh$26q$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1224971282 23250 172.30.248.37 (25 Oct 2008 21:48:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 25 Oct 2008 21:48:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:497246


"Ka Lee" <kaloklee@gmail.com> wrote in message <gdvpsh$26q$1@fred.mathworks.com>...
> .......
> for i=1:N
>      x=G(:,i)-g_bar;
>      S=S+(x*x'); 
> end
> 
> I am wondering if there is a way to compute S without the for-loop.  

 G2 = G-repmat(g_bar,1,N);
 S = G2*G2';

Roger Stafford