Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Insert zeros into a vector
Date: Wed, 24 Jun 2009 23:41:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 73
Message-ID: <h1udid$ro$1@fred.mathworks.com>
References: <h1ucbh$f5i$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1245886861 888 172.30.248.35 (24 Jun 2009 23:41:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 24 Jun 2009 23:41:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1875128
Xref: news.mathworks.com comp.soft-sys.matlab:550473


Got it!

>> B = reshape(A, 2, 6/2)

B =

     1     4     6
     3     5     7

>> B = cat(1,B, sparse(1,6/2))

B =

   (1,1)        1
   (2,1)        3
   (1,2)        4
   (2,2)        5
   (1,3)        6
   (2,3)        7

>> B = reshape(B, [], 1 )

B =

   (1,1)        1
   (2,1)        3
   (4,1)        4
   (5,1)        5
   (7,1)        6
   (8,1)        7

>> full(B)

ans =

     1
     3
     0
     4
     5
     0
     6
     7
     0



"Diego Lass" <dlISCool@gmail.com> wrote in message <h1ucbh$f5i$1@fred.mathworks.com>...
> 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
> 
>