element wise product matrix-vector

I have a 200x5 matrix (Y) that includes 5 time series and a 5x1 vector of weights (w). For each t (row of the matrix), I need to compute the following element-wise product:
How can I do that?
Thank you

 Accepted Answer

S_t=Y_t.*w';

3 Comments

Alex
Alex on 4 Apr 2020
Edited: Alex on 4 Apr 2020
It doesn't work because matrix dimensions don't agree, I think a for loop is necessary. I tried this but it doesn't work again
for i= 1:length(y)
s(i) = y.*w';
end
No, David's code does work. Matlab is smart enough to recognize, that the dimensions do not agree, so it performs it for each row.
But in theory, you are right, Alex. The Hadamard product requires to have matrices who's dimensions do match ;)
thank's

Sign in to comment.

More Answers (1)

Categories

Asked:

on 4 Apr 2020

Commented:

on 4 Apr 2020

Community Treasure Hunt

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

Start Hunting!