How to multiple a given element of a column vector across the elements of a row in a matrix, for each corresponding row.

I wish to multiple the elements of a row vector across the rows of the corresponding row of a matrix. Here's an example:
X = [1 2 3]' and y = [1 1 1; 1 1 1; 1 1 1] I want the first element of X to multiply across the first row of y, the 2nd element of x to multiply across the 2nd row of y, and so on, which should give:
output = [1 1 1; 2 2 2; 3 3 3].
I can do this with a complicated for-loop, but surely MATLAB has some elegant and compact way to handle this, especially for very large matrices and of arbitrary dimension, which is what I ultimately want to do.
Thanks for the help.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!