Code covered by the BSD License  

Highlights from
vecInsert.m

4.33333

4.3 | 3 ratings Rate this file 2 Downloads (last 30 days) File Size: 1.41 KB File ID: #21948

vecInsert.m

by Michael Stachowsky

 

30 Oct 2008

vecInsert(elemToInsert,position,vecIn) Insert elements into a vector at given positions

| Watch this File

File Information
Description

Works with 1xn and nx1 vectors.

Inserts a vector of elements into the given positions. elemToInsert is a
vector that can be as small as 1 element and as large as desired.
Position is an array of positions that can be as small as one element and
as large as the number of elements you wish to insert.

If position is smaller than the number of elements, this function will
assume that the remaining elements will be inserted sequentially.

If position is larger than the number of elements, this function will insert the
last element of elemToInsert at the remaining given positions.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
02 Nov 2008 B.

If I understand correctly, this function does nothing more than

x(pos) = values;

where x, pos and values are all vectors.

03 Nov 2008 Michael Stachowsky

Actually, x(pos) = values; will overwrite the existing vector elements. vecInsert will move the existing values so that nothing is overwritten.

05 Nov 2008 Jos (10584)

This looks reasonably OK, but could be improved. However, it misses a H1 line (first line of the help section used by lookfor to get the name of a function based on key words) and an example. Moreover, it fails on certain inputs, like test([99 100],[5 5],1:10), without proper error message.

And did you look at INSERTROWS which has similar functionality:
http://www.mathworks.com/matlabcentral/fileexchange/9984

20 Jan 2010 Mark Hard

Thanks very much. Hit a dead end on a project and needed something like this. INSERTROWS wouldn't work properly for me for some reason.

14 Apr 2011 Leonardo O. Iheme

Thanks for this life saver

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
vector insertion Michael Stachowsky 01 Nov 2008 02:43:29
resizing Michael Stachowsky 01 Nov 2008 02:43:29

Contact us at files@mathworks.com