<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237073</link>
    <title>MATLAB Central Newsreader - Vectorizing different parts of the same array</title>
    <description>Feed for thread: Vectorizing different parts of the same array</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>Mon, 06 Oct 2008 15:10:20 -0400</pubDate>
      <title>Vectorizing different parts of the same array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237073#603911</link>
      <author>Theodor Zouk</author>
      <description>Hi&lt;br&gt;
&lt;br&gt;
Im using a file containing data approximately the size of 1 Giga Byte. Now i gona partition this file into blocks (fragments) of the size of 4KB. (Then make some calculation on each fragment..). I know that i can use a for loop to read each fragment from the file and make my calculations.. but that resolves in an iteration of 250 000.&lt;br&gt;
Now i was thinking: &quot;ok, lets read say 10Mb of the file each iteration and then partition it into 4kb of fragments&quot;&lt;br&gt;
&lt;br&gt;
So I will now have an array k=1x10 240 000 elements long.&lt;br&gt;
I want to get k(1:n),where n=4096, make some calculation and then store the result in the first row in an matrix..... then jump to k(n+1:2*n),calculated, store the result in the second row in the matrix and then jump to k(2*n+1:3*n) and so on... Can this be vectorized? I have tried... but i dont think u can avoid an for loop here...&lt;br&gt;
&lt;br&gt;
//TEO</description>
    </item>
    <item>
      <pubDate>Mon, 06 Oct 2008 16:34:02 -0400</pubDate>
      <title>Re: Vectorizing different parts of the same array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237073#603938</link>
      <author>Adam </author>
      <description>&quot;Theodor Zouk&quot; &amp;lt;rebet4@hotmail.com&amp;gt; wrote &lt;br&gt;
&lt;br&gt;
&amp;gt; I want to get k(1:n),where n=4096, make some calculation and then store the result in the first row in an matrix..... then jump to k(n+1:2*n),calculated, store the result in the second row in the matrix and then jump to k(2*n+1:3*n) and so on... Can this be vectorized? I have tried... but i dont think u can avoid an for loop here...&lt;br&gt;
&lt;br&gt;
can you reshape to 4096xN and work on each column?&lt;br&gt;
&lt;br&gt;
~Adam</description>
    </item>
    <item>
      <pubDate>Mon, 06 Oct 2008 16:36:02 -0400</pubDate>
      <title>Re: Vectorizing different parts of the same array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237073#603940</link>
      <author>Adam </author>
      <description>&quot;Theodor Zouk&quot; &amp;lt;rebet4@hotmail.com&amp;gt; wrote&lt;br&gt;
&lt;br&gt;
ok, that wasn't very clear.&lt;br&gt;
&lt;br&gt;
reshape, then you should be able to apply functions that work down the columns.  Since you didn't say what calculations you're doing it's hard to offer advice towards a solution.&lt;br&gt;
&lt;br&gt;
~Adam</description>
    </item>
    <item>
      <pubDate>Mon, 06 Oct 2008 16:58:30 -0400</pubDate>
      <title>Re: Vectorizing different parts of the same array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237073#603944</link>
      <author>Walter Roberson</author>
      <description>Theodor Zouk wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; So I will now have an array k=1x10 240 000 elements long.&lt;br&gt;
&amp;gt; I want to get k(1:n),where n=4096, make some calculation and then store the result&lt;br&gt;
&amp;gt; in the first row in an matrix..... then jump to k(n+1:2*n),calculated, &lt;br&gt;
&amp;gt; tore the result in the second row in the matrix and then jump to k(2*n+1:3*n) and so on...&lt;br&gt;
&amp;gt;  Can this be vectorized? I have tried... but i dont think u can avoid an for loop here...&lt;br&gt;
&lt;br&gt;
mat2cell() can break it up into cells of the appropriate size; then you can&lt;br&gt;
use cellfun() (but cellfun is not always faster than a for loop.)</description>
    </item>
    <item>
      <pubDate>Mon, 06 Oct 2008 17:18:02 -0400</pubDate>
      <title>Re: Vectorizing different parts of the same array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237073#603954</link>
      <author>Theodor Zouk</author>
      <description>&quot;Adam &quot; &amp;lt;not.real@email.com&amp;gt; wrote in message &amp;lt;gcdelq$5he$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Theodor Zouk&quot; &amp;lt;rebet4@hotmail.com&amp;gt; wrote &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I want to get k(1:n),where n=4096, make some calculation and then store the result in the first row in an matrix..... then jump to k(n+1:2*n),calculated, store the result in the second row in the matrix and then jump to k(2*n+1:3*n) and so on... Can this be vectorized? I have tried... but i dont think u can avoid an for loop here...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; can you reshape to 4096xN and work on each column?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ~Adam&lt;br&gt;
&lt;br&gt;
No i can't reshape... because i have a vector.&lt;br&gt;
My problem is more like: how can i access each element in a part of an vector then store those values (or at best be able to calculate things in parallell) and then continuing to read elements in the same vector from were i stopped reading the first time... &lt;br&gt;
&lt;br&gt;
I want to vectorize this for example:&lt;br&gt;
&lt;br&gt;
vec=(1:10);&lt;br&gt;
mat= zeros(5,2);&lt;br&gt;
k=1;&lt;br&gt;
&lt;br&gt;
for i=1:2:10&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mat(k,:)= vec(i:i+1);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;k=k+1;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;</description>
    </item>
    <item>
      <pubDate>Mon, 06 Oct 2008 21:37:01 -0400</pubDate>
      <title>Re: Vectorizing different parts of the same array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237073#603999</link>
      <author>Jos </author>
      <description>&quot;Theodor Zouk&quot; &amp;lt;rebet4@hotmail.com&amp;gt; wrote in message &amp;lt;gcdh8a$3lm$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Adam &quot; &amp;lt;not.real@email.com&amp;gt; wrote in message &amp;lt;gcdelq$5he$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Theodor Zouk&quot; &amp;lt;rebet4@hotmail.com&amp;gt; wrote &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; I want to get k(1:n),where n=4096, make some calculation and then store the result in the first row in an matrix..... then jump to k(n+1:2*n),calculated, store the result in the second row in the matrix and then jump to k(2*n+1:3*n) and so on... Can this be vectorized? I have tried... but i dont think u can avoid an for loop here...&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; can you reshape to 4096xN and work on each column?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; ~Adam&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; No i can't reshape... because i have a vector.&lt;br&gt;
&lt;br&gt;
Wrong!&lt;br&gt;
&lt;br&gt;
&amp;gt; My problem is more like: how can i access each element in a part of an vector then store those values (or at best be able to calculate things in parallell) and then continuing to read elements in the same vector from were i stopped reading the first time... &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I want to vectorize this for example:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; vec=(1:10);&lt;br&gt;
&amp;gt; mat= zeros(5,2);&lt;br&gt;
&amp;gt; k=1;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:2:10&lt;br&gt;
&amp;gt;     mat(k,:)= vec(i:i+1);&lt;br&gt;
&amp;gt;     k=k+1;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&lt;br&gt;
vec = 1:10 ;&lt;br&gt;
mat = reshape(vec,2,[]).'&lt;br&gt;
&lt;br&gt;
Jos</description>
    </item>
    <item>
      <pubDate>Tue, 07 Oct 2008 06:17:03 -0400</pubDate>
      <title>Re: Vectorizing different parts of the same array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237073#604041</link>
      <author>Theodor Zouk</author>
      <description>&quot;Jos &quot; &amp;lt;DELjos@jasenDEL.nl&amp;gt; wrote in message &amp;lt;gce0dt$9j6$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Theodor Zouk&quot; &amp;lt;rebet4@hotmail.com&amp;gt; wrote in message &amp;lt;gcdh8a$3lm$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Adam &quot; &amp;lt;not.real@email.com&amp;gt; wrote in message &amp;lt;gcdelq$5he$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &quot;Theodor Zouk&quot; &amp;lt;rebet4@hotmail.com&amp;gt; wrote &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &amp;gt; I want to get k(1:n),where n=4096, make some calculation and then store the result in the first row in an matrix..... then jump to k(n+1:2*n),calculated, store the result in the second row in the matrix and then jump to k(2*n+1:3*n) and so on... Can this be vectorized? I have tried... but i dont think u can avoid an for loop here...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; can you reshape to 4096xN and work on each column?&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; ~Adam&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; No i can't reshape... because i have a vector.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Wrong!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; My problem is more like: how can i access each element in a part of an vector then store those values (or at best be able to calculate things in parallell) and then continuing to read elements in the same vector from were i stopped reading the first time... &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I want to vectorize this for example:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; vec=(1:10);&lt;br&gt;
&amp;gt; &amp;gt; mat= zeros(5,2);&lt;br&gt;
&amp;gt; &amp;gt; k=1;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for i=1:2:10&lt;br&gt;
&amp;gt; &amp;gt;     mat(k,:)= vec(i:i+1);&lt;br&gt;
&amp;gt; &amp;gt;     k=k+1;&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; vec = 1:10 ;&lt;br&gt;
&amp;gt; mat = reshape(vec,2,[]).'&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Jos&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
It works.&lt;br&gt;
thank you Jos&lt;br&gt;
&lt;br&gt;
/TEO</description>
    </item>
    <item>
      <pubDate>Tue, 07 Oct 2008 06:41:02 -0400</pubDate>
      <title>Re: Vectorizing different parts of the same array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237073#604045</link>
      <author>Bruno Luong</author>
      <description>&quot;Theodor Zouk&quot; at time t1&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; No i can't reshape... because i have a vector.&lt;br&gt;
&lt;br&gt;
&quot;Theodor Zouk&quot; at time t2&lt;br&gt;
&lt;br&gt;
&amp;gt; It works.&lt;br&gt;
&amp;gt; thank you Jos&lt;br&gt;
&lt;br&gt;
Conclusion at the time t2 &quot;Theodor Zouk&quot; is not the same than &quot;Theodor Zouk&quot; at the time t1: He has been reshaped. ;-)&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Tue, 07 Oct 2008 09:02:05 -0400</pubDate>
      <title>Re: Vectorizing different parts of the same array</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237073#604070</link>
      <author>Theodor Zouk</author>
      <description>&quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;gcf09u$kjq$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Theodor Zouk&quot; at time t1&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; No i can't reshape... because i have a vector.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &quot;Theodor Zouk&quot; at time t2&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; It works.&lt;br&gt;
&amp;gt; &amp;gt; thank you Jos&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Conclusion at the time t2 &quot;Theodor Zouk&quot; is not the same than &quot;Theodor Zouk&quot; at the time t1: He has been reshaped. ;-)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Bruno&lt;br&gt;
&lt;br&gt;
It's true :-) it seems that i didnt really understand the reshape function the first time...</description>
    </item>
  </channel>
</rss>

