MATLAB: How to multiply and concatenate at same time

concatenatematrix manipulationmultiply

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

Best Answer

Kronecker product would be suitable if we could apply it along a given dimension, but it seems that we can't. As an alternative, look at the following and let me know if there is anything that you don't understand:
>> A = [1, 2, 3; 4, 5, 6] ;
>> B = [7, 8; 9, 10] ;
>> C = reshape(repmat(A, size(B,2), 1), size(A,1), []) .* repmat(B, 1, size(A,2))
C =
7 8 14 16 21 24
36 40 45 50 54 60