I need to multiply a matrix A with each element of another matrix B. The result should be stored in one large matrix, C. This should work for arbitrarily large matrices.

To give a specific example:
Take to matrices AandB

One solution would be to loop over all elements of B but this is probably inefficient and allocating the results of each iteration into matrix Cmight get tricky.

Any better ideas?

I’m sorry if this was asked before. If so, please just refer me to the right topic.