<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238157</link>
    <title>MATLAB Central Newsreader - trying to avoid using a for loop</title>
    <description>Feed for thread: trying to avoid using a for loop</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sat, 25 Oct 2008 18:52:01 -0400</pubDate>
      <title>trying to avoid using a for loop</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238157#607305</link>
      <author>Ka Lee</author>
      <description>Hi.&lt;br&gt;
&lt;br&gt;
I am trying to compute S.&lt;br&gt;
S is a m by m matrix.  &lt;br&gt;
&lt;br&gt;
To create S, I use the following information.&lt;br&gt;
&lt;br&gt;
G is a m by N matrix.&lt;br&gt;
G(:,i) is the ith column of G.&lt;br&gt;
g_bar is a m by 1 vector.&lt;br&gt;
&lt;br&gt;
This for-loop can compute S.&lt;br&gt;
S=[];&lt;br&gt;
for i=1:N&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x=G(:,i)-g_bar;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;S=S+(x*x'); &lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
I am wondering if there is a way to compute S without the for-loop.  Thanks.</description>
    </item>
    <item>
      <pubDate>Sat, 25 Oct 2008 19:19:02 -0400</pubDate>
      <title>Re: trying to avoid using a for loop</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238157#607311</link>
      <author>Budias Aao</author>
      <description>&quot;Ka Lee&quot; &amp;lt;kaloklee@gmail.com&amp;gt; wrote in message &amp;lt;gdvpsh$26q$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am trying to compute S.&lt;br&gt;
&amp;gt; S is a m by m matrix.  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; To create S, I use the following information.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; G is a m by N matrix.&lt;br&gt;
&amp;gt; G(:,i) is the ith column of G.&lt;br&gt;
&amp;gt; g_bar is a m by 1 vector.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This for-loop can compute S.&lt;br&gt;
&amp;gt; S=[];&lt;br&gt;
&amp;gt; for i=1:N&lt;br&gt;
&amp;gt;      x=G(:,i)-g_bar;&lt;br&gt;
&amp;gt;      S=S+(x*x'); &lt;br&gt;
&amp;gt; end&lt;br&gt;
&lt;br&gt;
&amp;gt; I am wondering if there is a way to compute S without the for-loop.  Thanks.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
What is the problem with the for loop?&lt;br&gt;
Does it give a wrong result?&lt;br&gt;
Is it not pretty?</description>
    </item>
    <item>
      <pubDate>Sat, 25 Oct 2008 21:48:02 -0400</pubDate>
      <title>Re: trying to avoid using a for loop</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238157#607325</link>
      <author>Roger Stafford</author>
      <description>&quot;Ka Lee&quot; &amp;lt;kaloklee@gmail.com&amp;gt; wrote in message &amp;lt;gdvpsh$26q$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; .......&lt;br&gt;
&amp;gt; for i=1:N&lt;br&gt;
&amp;gt;      x=G(:,i)-g_bar;&lt;br&gt;
&amp;gt;      S=S+(x*x'); &lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am wondering if there is a way to compute S without the for-loop.  &lt;br&gt;
&lt;br&gt;
&amp;nbsp;G2 = G-repmat(g_bar,1,N);&lt;br&gt;
&amp;nbsp;S = G2*G2';&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
  </channel>
</rss>

