<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158795</link>
    <title>MATLAB Central Newsreader - Create a new vector from a current vector</title>
    <description>Feed for thread: Create a new vector from a current vector</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, 05 Nov 2007 15:04:45 -0500</pubDate>
      <title>Create a new vector from a current vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158795#399869</link>
      <author>Amir Safari</author>
      <description>&lt;br&gt;
Hi MATLAB users,&lt;br&gt;
&lt;br&gt;
Suppose we have a matrix or vector with only one column of &lt;br&gt;
length 20.&lt;br&gt;
&lt;br&gt;
A=[1,3,3,4,2,4,3,5,5,2,4,3,7,4,2,4,1,4,2,3];&lt;br&gt;
&lt;br&gt;
My question is that how to create a new matrix or vector &lt;br&gt;
from A so that the new vector be sums of every 4 values of &lt;br&gt;
A. Therefore the new vector of B will have a length of 5.&lt;br&gt;
&lt;br&gt;
B=[11,14,14,17,10];&lt;br&gt;
&lt;br&gt;
How to create B from A?&lt;br&gt;
&lt;br&gt;
Thank you very much.&lt;br&gt;
Amir</description>
    </item>
    <item>
      <pubDate>Mon, 05 Nov 2007 15:26:40 -0500</pubDate>
      <title>Re: Create a new vector from a current vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158795#399874</link>
      <author>John D'Errico</author>
      <description>&quot;Amir Safari&quot; &amp;lt;amsa36060@yahoo.com&amp;gt; wrote in message &amp;lt;fgnbec$21u&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hi MATLAB users,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Suppose we have a matrix or vector with only one column of &lt;br&gt;
&amp;gt; length 20.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; A=[1,3,3,4,2,4,3,5,5,2,4,3,7,4,2,4,1,4,2,3];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; My question is that how to create a new matrix or vector &lt;br&gt;
&amp;gt; from A so that the new vector be sums of every 4 values of &lt;br&gt;
&amp;gt; A. Therefore the new vector of B will have a length of 5.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; B=[11,14,14,17,10];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; How to create B from A?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thank you very much.&lt;br&gt;
&amp;gt; Amir&lt;br&gt;
&lt;br&gt;
Easy enough.&lt;br&gt;
&lt;br&gt;
A=[1,3,3,4,2,4,3,5,5,2,4,3,7,4,2,4,1,4,2,3];&lt;br&gt;
&lt;br&gt;
C = repmat({ones(4,1)},1,5);&lt;br&gt;
A*blkdiag(C{:})&lt;br&gt;
&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;11    14    14    17    10&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Mon, 05 Nov 2007 15:42:07 -0500</pubDate>
      <title>Re: Create a new vector from a current vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158795#399881</link>
      <author>nor ki</author>
      <description>&quot;Amir Safari&quot; &amp;lt;amsa36060@yahoo.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;fgnbec$21u$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hi MATLAB users,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Suppose we have a matrix or vector with only one column of &lt;br&gt;
&amp;gt; length 20.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; A=[1,3,3,4,2,4,3,5,5,2,4,3,7,4,2,4,1,4,2,3];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; My question is that how to create a new matrix or vector &lt;br&gt;
&amp;gt; from A so that the new vector be sums of every 4 values of &lt;br&gt;
&amp;gt; A. Therefore the new vector of B will have a length of 5.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; B=[11,14,14,17,10];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; How to create B from A?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thank you very much.&lt;br&gt;
&amp;gt; Amir&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
aa = reshape(A, 4,numel(A)/4);&lt;br&gt;
B = sum(aa)&lt;br&gt;
&lt;br&gt;
should do </description>
    </item>
    <item>
      <pubDate>Mon, 05 Nov 2007 16:03:15 -0500</pubDate>
      <title>Re: Create a new vector from a current vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158795#399889</link>
      <author>us</author>
      <description>Amir Safari:&lt;br&gt;
&amp;lt;SNIP wants to sum subvecs of a larger one&lt;br&gt;
&lt;br&gt;
others have shown you the typical way to do it...&lt;br&gt;
one of the more versatile solutions is outlined below&lt;br&gt;
&lt;br&gt;
% the data&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a=[1,3,3,4,2,4,3,5,5,2,4,3,7,4,2,4,1,4,2,3];&lt;br&gt;
% - define the starting indices of your subvecs&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;abeg=[1,6,7,10,18];&lt;br&gt;
% the engine&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;aend=[abeg(2:end)-1,numel(a)];&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r=arrayfun(@(b,e) sum(a(b:e)),abeg,aend);&lt;br&gt;
% the result&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[abeg;aend] % the subvecs&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r&lt;br&gt;
&lt;br&gt;
us</description>
    </item>
    <item>
      <pubDate>Mon, 05 Nov 2007 16:25:41 -0500</pubDate>
      <title>Re: Create a new vector from a current vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158795#399895</link>
      <author>nor ki</author>
      <description>&quot;us &quot; &amp;lt;us@neurol.unizh.ch&amp;gt; wrote in message&lt;br&gt;
&amp;lt;fgnes3$mop$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Amir Safari:&lt;br&gt;
&amp;gt; &amp;lt;SNIP wants to sum subvecs of a larger one&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; others have shown you the typical way to do it...&lt;br&gt;
&amp;gt; one of the more versatile solutions is outlined below&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % the data&lt;br&gt;
&amp;gt;      a=[1,3,3,4,2,4,3,5,5,2,4,3,7,4,2,4,1,4,2,3];&lt;br&gt;
&amp;gt; % - define the starting indices of your subvecs&lt;br&gt;
&amp;gt;      abeg=[1,6,7,10,18];&lt;br&gt;
&amp;gt; % the engine&lt;br&gt;
&amp;gt;      aend=[abeg(2:end)-1,numel(a)];&lt;br&gt;
&amp;gt;      r=arrayfun(@(b,e) sum(a(b:e)),abeg,aend);&lt;br&gt;
&amp;gt; % the result&lt;br&gt;
&amp;gt;      [abeg;aend] % the subvecs&lt;br&gt;
&amp;gt;      r&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; us&lt;br&gt;
&lt;br&gt;
sorry i don&#180;t get the same results</description>
    </item>
    <item>
      <pubDate>Mon, 05 Nov 2007 17:20:37 -0500</pubDate>
      <title>Re: Create a new vector from a current vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158795#399912</link>
      <author>us</author>
      <description>nor ki:&lt;br&gt;
&amp;lt;SNIP found a mistake in &amp;lt;us&amp;gt;'s reply - did he/she?&lt;br&gt;
&lt;br&gt;
&amp;gt; sorry i don&#180;t get the same results...&lt;br&gt;
&lt;br&gt;
what results? i did not show them...&lt;br&gt;
&lt;br&gt;
% here they are&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[abeg;aend]&lt;br&gt;
%     1     6     7    10    18&lt;br&gt;
%     5     6     9    17    20&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r&lt;br&gt;
%    13     4    13    27     9&lt;br&gt;
&lt;br&gt;
% now, compare a few results, eg&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sum(a(1:5)) % = 13&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sum(a(10:17)) % = 27&lt;br&gt;
% which seem ok...&lt;br&gt;
&lt;br&gt;
note: i said &amp;lt;more versatile&amp;gt;&lt;br&gt;
us</description>
    </item>
    <item>
      <pubDate>Mon, 05 Nov 2007 20:52:29 -0500</pubDate>
      <title>Re: Create a new vector from a current vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158795#399943</link>
      <author>PB</author>
      <description>Den Mon, 05 Nov 2007 15:04:45 +0000 skrev Amir Safari:&lt;br&gt;
&lt;br&gt;
&amp;gt; Hi MATLAB users,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Suppose we have a matrix or vector with only one column of length 20.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; A=[1,3,3,4,2,4,3,5,5,2,4,3,7,4,2,4,1,4,2,3];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; My question is that how to create a new matrix or vector from A so that&lt;br&gt;
&amp;gt; the new vector be sums of every 4 values of A. Therefore the new vector&lt;br&gt;
&amp;gt; of B will have a length of 5.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; B=[11,14,14,17,10];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; How to create B from A?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thank you very much.&lt;br&gt;
&amp;gt; Amir&lt;br&gt;
&lt;br&gt;
Another solution&lt;br&gt;
&lt;br&gt;
b=filter([1 1 1 1],1,A);&lt;br&gt;
b=b(4:4:end)&lt;br&gt;
&lt;br&gt;
/PB</description>
    </item>
    <item>
      <pubDate>Tue, 06 Nov 2007 11:57:11 -0500</pubDate>
      <title>Re: Create a new vector from a current vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158795#400017</link>
      <author>nor ki</author>
      <description>&quot;us &quot; &amp;lt;us@neurol.unizh.ch&amp;gt; wrote in message&lt;br&gt;
&amp;lt;fgnjd5$ss1$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; nor ki:&lt;br&gt;
&amp;gt; &amp;lt;SNIP found a mistake in &amp;lt;us&amp;gt;'s reply - did he/she?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; sorry i don&#180;t get the same results...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; what results? i did not show them...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % here they are&lt;br&gt;
&amp;gt;      [abeg;aend]&lt;br&gt;
&amp;gt; %     1     6     7    10    18&lt;br&gt;
&amp;gt; %     5     6     9    17    20&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;      r&lt;br&gt;
&amp;gt; %    13     4    13    27     9&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % now, compare a few results, eg&lt;br&gt;
&amp;gt;      sum(a(1:5)) % = 13&lt;br&gt;
&amp;gt;      sum(a(10:17)) % = 27&lt;br&gt;
&amp;gt; % which seem ok...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; note: i said &amp;lt;more versatile&amp;gt;&lt;br&gt;
&amp;gt; us&lt;br&gt;
&lt;br&gt;
sorry for my stupid remark &lt;br&gt;
i just like to understand your solution&lt;br&gt;
&lt;br&gt;
the original desired result was&lt;br&gt;
B=[11,14,14,17,10];&lt;br&gt;
&lt;br&gt;
then &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;abeg = 1:4:numel(a)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;aend = 4:4:numel(a)&lt;br&gt;
would do it?&lt;br&gt;
&lt;br&gt;
nor ki</description>
    </item>
  </channel>
</rss>

