
Re: Insert values into a matrix
Posted:
Jul 15, 2013 7:40 PM


"Max " <mshestov@gmail.com> wrote in message news:ks201c$bok$1@newscl01ah.mathworks.com... > Hi guys, I'm having a bit of a brain fart here. > > Say you have a matrix A = [1,2,3,4,5] > and a logical vector B = [1,0,0,1,1,1,0,1] > > Where I want to stretch A to the Length of B by inserting 0's where 0's > locations appear in B. > > Basically, how can I turn matrix A into this [1,0,0,2,3,4,0,5] using B > > Appreciate the help guys. > > Max >
Try this:
A = [1,2,3,4,5] B = [1,0,0,1,1,1,0,1] B = logical(B); C(B) = A C = 1 0 0 2 3 4 0 5
 Loren
http://blogs.mathworks.com/loren

