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

 채택된 답변

David Hill
David Hill 2020년 4월 4일

0 개 추천

S_t=Y_t.*w';

댓글 수: 3

Alex
Alex 2020년 4월 4일
편집: Alex 2020년 4월 4일
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
Florian Floh
Florian Floh 2020년 4월 4일
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 ;)
Alex
Alex 2020년 4월 4일
thank's

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Torsten
Torsten 2020년 4월 4일

0 개 추천

Y_t = bsxfun(@times,Y_t,w)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2020년 4월 4일

댓글:

2020년 4월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by