"Matrix dimensions must agree" despite using .*
조회 수: 1 (최근 30일)
이전 댓글 표시
Matrix dimensions must agree.
Error in nnCostFunction (line 74) delta1_h = (d2).*(X1_tr);
d2 and X1_tr are the two vectors wich have sizes unsuitable for matrix multiplication, but my goal is element-wise multiplication and somehow Matlab fails to do it. Can you please help me with this problem?
In the console I've tried element-wise multiplication of [1 2 3] and [2; 3; 4; 5]. It was alright. Wonder what may be wrong here.
Thank you.
댓글 수: 0
답변 (1개)
Star Strider
2017년 4월 20일
It’s called ‘implicit expansion’ and is new in R2016b.
The ‘traditional’ (and my preferred) way to do this is to use the bsxfun function to achieve the same result:
a = [1 2 3];
b = [2; 3; 4; 5];
q1 = bsxfun(@times, a, b);
q2 = bsxfun(@times, b, a);
You will get the same result regardless of the way the operators are entered.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!