Matrix dimension not agree in matrix vector operation
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
I'm trying to perform matrix vector element wise operation for example
rand(3) - [1,2,3]
I get error of Matrix dimensions must agree. However, this would work on my friend's machine. Similarly
rand(3) .* [1,2,3]
would not work on my machine but on hers. I'm expecting same behavior as bsxfun(@times, rand(3), [1,2,3]) My Matlab version is 2015b and hers' is 2016b. I thought this was supported long time ago?
댓글 수: 0
답변 (2개)
David Goodmanson
2016년 10월 30일
편집: David Goodmanson
2016년 10월 30일
0 개 추천
Hello Christine, One of the quirkier aspects of Matlab is that rand(n) and some similar functions give you a square matrix, 3x3 in this case, so neither of the commands you show will to work. You can't subtract a row vector from a matrix, at least not with that syntax. It is not clear what is happening with your friend's setup but those commands will not work in Matlab 2016b either.
댓글 수: 0
Steven Lord
2016년 10월 30일
0 개 추천
The feature where some operators (like the minus operator - ) automatically perform implicit expansion was introduced in release R2016b. You can read more about it on Loren's blog. For earlier releases you will need to use bsxfun.
댓글 수: 0
이 질문은 마감되었습니다.
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!