So I have the following matrices:
A = [1 2 3; 4 5 6];
B = [0.5 2 3];
I\'m writing a function in MATLAB that will allow me to multiply a vec
MATLAB already has functionality to do this in the bsxfun function. bsxfun
will take two matrices and duplicate singleton dimensions until the matrices are the same size, then perform a binary operation on the two matrices. So, for your example, you would simply do the following:
C = bsxfun(@times,mat,vec);