<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/244352</link>
    <title>MATLAB Central Newsreader - looping/vectorising issue...</title>
    <description>Feed for thread: looping/vectorising issue...</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>Thu, 12 Feb 2009 16:57:01 -0500</pubDate>
      <title>Re: looping/vectorising issue...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/244352#627926</link>
      <author>Roger Stafford</author>
      <description>&quot;Rich &quot; &amp;lt;richardwood@removethishotmail.com&amp;gt; wrote in message &amp;lt;gn0vhg$rn$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Anyone have any suggestions on how to vectorise this loop? (by vectorise, i guess i mean converting to matrix multiplication)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I'm at a loss!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; dimensions are:&lt;br&gt;
&amp;gt; z1(m,n)&lt;br&gt;
&amp;gt; z2(m,k)&lt;br&gt;
&amp;gt; z3(m,n*k)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:size(z1,1)&lt;br&gt;
&amp;gt;     z3(i,:)=reshape(z1(i,:)'*z2(i,:),1,[]);&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; thanks heaps!&lt;br&gt;
&lt;br&gt;
&amp;nbsp;[I,J] = ndgrid(1:n,1:k);&lt;br&gt;
&amp;nbsp;z3 = z1(:,I).*z2(:,J);&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Fri, 13 Feb 2009 10:06:02 -0500</pubDate>
      <title>Re: looping/vectorising issue...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/244352#628086</link>
      <author>Rich </author>
      <description>thanks Roger, you are a legend, and have saved me 75% of my runtime!</description>
    </item>
    <item>
      <pubDate>Thu, 12 Feb 2009 11:01:04 -0500</pubDate>
      <title>looping/vectorising issue...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/244352#627856</link>
      <author>Rich </author>
      <description>Anyone have any suggestions on how to vectorise this loop? (by vectorise, i guess i mean converting to matrix multiplication)&lt;br&gt;
&lt;br&gt;
I'm at a loss!&lt;br&gt;
&lt;br&gt;
dimensions are:&lt;br&gt;
z1(m,n)&lt;br&gt;
z2(m,k)&lt;br&gt;
z3(m,n*k)&lt;br&gt;
&lt;br&gt;
for i=1:size(z1,1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;z3(i,:)=reshape(z1(i,:)'*z2(i,:),1,[]);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
thanks heaps!</description>
    </item>
    <item>
      <pubDate>Thu, 18 Jun 2009 11:40:20 -0400</pubDate>
      <title>Re: looping/vectorising issue...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/244352#658427</link>
      <author>Rich </author>
      <description>So I hit memory problems as soon as I do this for big matrices (thousands by thousands), maybe I should have mentioned that before.&lt;br&gt;
So, does anyone have a less memory intensive version?&lt;br&gt;
&lt;br&gt;
I am generally working with sparse matrices, so I think I have to kick my brain into gear enough to work out how to use the find command in this context. But any pointers would be much appreciated!&lt;br&gt;
&lt;br&gt;
thanks</description>
    </item>
    <item>
      <pubDate>Thu, 18 Jun 2009 13:53:09 -0400</pubDate>
      <title>Re: looping/vectorising issue...</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/244352#658463</link>
      <author>Rune Allnor</author>
      <description>On 18 Jun, 13:40, &quot;Rich &quot; &amp;lt;richardw...@removethishotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; So I hit memory problems as soon as I do this for big matrices (thousands by thousands), maybe I should have mentioned that before.&lt;br&gt;
&amp;gt; So, does anyone have a less memory intensive version?&lt;br&gt;
&lt;br&gt;
That's the problem with 'vectorization': You gain some speed at&lt;br&gt;
the expense of memory.&lt;br&gt;
&lt;br&gt;
If you're hitting the memory wall, you have two options:&lt;br&gt;
&lt;br&gt;
1) Buy a bigger computer.&lt;br&gt;
2) Implement a MEX routine in C or C++.&lt;br&gt;
&lt;br&gt;
Rune</description>
    </item>
  </channel>
</rss>

