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: repmat, reshape, bsxfun
Replies: 12   Last Post: Jan 23, 2012 11:08 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Pag Max

Posts: 13
Registered: 5/16/11
repmat, reshape, bsxfun
Posted: Jan 20, 2012 1:00 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Is there a smarter or shorter way to do this than what I have done? (Of course withot loop!!). I am thinking there is something repetitive in my solution
c is tiled in third dimension as many times as elements in b and then each tile is scaled by corresponding element in b.

c=[1 2 3;4 5 6];
b=[1 2 3 4 5];
a=bsxfun(@times,repmat(c,[1 1 numel(b)]),reshape(b,[1 1 numel(b)]));

gives
a=
a(:,:,1) =

1 2 3
4 5 6

a(:,:,2) =

2 4 6
8 10 12

a(:,:,3) =

3 6 9
12 15 18

a(:,:,4) =

4 8 12
16 20 24

a(:,:,5) =
5 10 15
20 25 30



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.