Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!o80g2000hse.googlegroups.com!not-for-mail
From:  somdeb <somdeb@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Inserting elements in a vector
Date: Mon, 24 Sep 2007 15:27:29 -0000
Organization: http://groups.google.com
Lines: 8
Message-ID: <1190647649.920687.281800@o80g2000hse.googlegroups.com>
NNTP-Posting-Host: 75.85.183.124
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1190647650 10281 127.0.0.1 (24 Sep 2007 15:27:30 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 24 Sep 2007 15:27:30 +0000 (UTC)
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: o80g2000hse.googlegroups.com; posting-host=75.85.183.124;
Xref: news.mathworks.com comp.soft-sys.matlab:429939


I have a vector v1 of L1 elements. I need to insert elements of
another vector v2 of L2 elements (L2<L1) into known positions of v1.

What is the fastest way to do this? Right now I preallocate L1+L2
elements for v1 and for every position I have to insert a sample, I
right-shift all the elements of v1 to the right of that position and
then insert the value. This is taking a long time.