Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Insert values into a matrix
Replies: 2   Last Post: Jul 15, 2013 8:04 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Loren Shure

Posts: 977
Registered: 12/7/04
Re: Insert values into a matrix
Posted: Jul 15, 2013 7:40 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


"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




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.