how to multiply and concatenate at same time?
Show older comments
Dear Matlab guys, I am wondering how to "multiply and concatenate" at same time? Let me write a simple example:
a = [ a b c ; d e f ]
b = [ g h ; i j ]
my idea is to arrive at this:
c = [ ag ah bg bh cg ch ; di dj ei ej fi fj ]
To present it this way I was thinking about the so-called Kronecker product, however I do not think that is the right thing though, since it create hugher matrix. For-loops is possible to do it, but I search for an easier way, - if it exists ?...
thanks in advance, -best Martin B
Accepted Answer
More Answers (1)
Roger Stafford
on 27 Apr 2013
A method using 'bsxfun':
A = [ a b c ; d e f ];
B = [ g h ; i j ];
[m,n] = size(A);
C = reshape(bsxfun(@times,reshape(A,[m,1,n]),B),m,[]);
1 Comment
Cedric
on 27 Apr 2013
Neat!
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!