Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!news.glorb.com!postnews.google.com!d7g2000prl.googlegroups.com!not-for-mail
From: Nathan <ngreco32@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Insert zeros into a vector
Date: Wed, 24 Jun 2009 16:34:02 -0700 (PDT)
Organization: http://groups.google.com
Lines: 40
Message-ID: <12b6cbfe-0a0f-4a30-b828-fb366a8edbd7@d7g2000prl.googlegroups.com>
References: <h1ucbh$f5i$1@fred.mathworks.com>
NNTP-Posting-Host: 198.206.219.34
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1245886442 25947 127.0.0.1 (24 Jun 2009 23:34:02 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 24 Jun 2009 23:34:02 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: d7g2000prl.googlegroups.com; posting-host=198.206.219.34; 
	posting-account=_KeVcAoAAAB7j3xn35ujaQ0BoQhuzwJP
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.11) 
	Gecko/2009060215 Firefox/3.0.11,gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 wwwproxy-son-ca-02.ca.sandia.gov:80 (squid/2.5.STABLE14)
Xref: news.mathworks.com comp.soft-sys.matlab:550472


On Jun 24, 4:20 pm, "Diego Lass" <dlISC...@gmail.com> wrote:
> Hi,
> I want to insert zeros into a vector in various positions.  But not necessarily every other elements.  For example
> A = [ 1; 3; 4 ;5 ;6;7]
> A =
>      1
>      3
>      4
>      5
>      6
>      7
> I want to insert at the every 3 rd positon
>      1
>      3
>      0
>      4
>      5
>      0
>      6
>      7
>      0
> What is the most efficient way of doing this?
> Thanks.
> Diego

http://www.mathworks.ch/matlabcentral/newsreader/view_thread/156659

% the data
     v=1:7;
     w=[0,0,0];
     pos=[3,6,9];
% the engine
     tf=false(1,numel(v)+numel(w));
     r=double(tf);
     tf(pos)=true;
     r(tf)=w;
     r(~tf)=v;
% the result
     r