Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Pag Max
Posts:
13
Registered:
5/16/11


repmat, reshape, bsxfun
Posted:
Jan 20, 2012 1:00 PM


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



