<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156659</link>
    <title>MATLAB Central Newsreader - Inserting elements in a vector</title>
    <description>Feed for thread: Inserting elements in a vector</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2010 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, 24 Sep 2007 15:27:29 -0400</pubDate>
      <title>Inserting elements in a vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156659#393718</link>
      <author> somdeb</author>
      <description>I have a vector v1 of L1 elements. I need to insert elements of&lt;br&gt;
another vector v2 of L2 elements (L2&amp;lt;L1) into known positions of v1.&lt;br&gt;
&lt;br&gt;
What is the fastest way to do this? Right now I preallocate L1+L2&lt;br&gt;
elements for v1 and for every position I have to insert a sample, I&lt;br&gt;
right-shift all the elements of v1 to the right of that position and&lt;br&gt;
then insert the value. This is taking a long time.&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Mon, 24 Sep 2007 15:51:31 -0400</pubDate>
      <title>Re: Inserting elements in a vector</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156659#393727</link>
      <author>us</author>
      <description>somdeb:&lt;br&gt;
&amp;lt;SNIP vec acrobatics...&lt;br&gt;
&lt;br&gt;
one of the many solutions&lt;br&gt;
&lt;br&gt;
% the data&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;v=1:10;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;w=[-10,-20,-30];&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pos=[2,6,7];&lt;br&gt;
% the engine&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tf=false(1,numel(v)+numel(w));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r=double(tf);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tf(pos)=true;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r(tf)=w;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r(~tf)=v;&lt;br&gt;
% the result&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r&lt;br&gt;
&lt;br&gt;
us&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
