MATLAB: Help I need matlab code that multiply each element in each coulmn by a each element in avector with the same length

matrices

help I need matlab code that multiply each element in each coulmn by a each element in avector with the same length

Best Answer

Use bsxfun:
m = rand(10,5);
v = rand(10,1);
vm = bsxfun(@times, v, m);
Here, ‘m’ is the matrix, ‘v’ is the vector, and ‘vm’ is the element-by-element product of the columns of ‘m’ and column vector ‘v’.