".*" does not work need help
조회 수: 2 (최근 30일)
이전 댓글 표시
https://www.mathworks.com/help/matlab/ref/times.html
The documentation above is for element-wise multiplication.
When I try to code one of the examples in there, it gives me an error : "Error using .* Matrix dimensions must agree."
a = [1 2 3]
a = 1×3
1 2 3
b = (1:6)'
b = 6×1
1
2
3
4
5
6
a.*b
ans = 6×3
1 2 3
2 4 6
3 6 9
4 8 12
5 10 15
6 12 18
It also does not work with what I tried at the beginning and also gives me the same error (reason why I looked for the documentation):
theta = 1X2 matrix
X = 5X2 matrix
answer = theta.*X
I also tried:
times(theta,X)
which does not work as well
I need someone to confirm if it works on their version of the matlab and if it does work what could possibly be the problem on mine?
My version of the matlab is the academic version but, I believe it should work just like the commercial one and I believe ".*" worked for me before ...
Thank you
댓글 수: 1
Stephen23
2018년 6월 23일
편집: Stephen23
2018년 6월 23일
@Yildirim Kocoglu: what release of MATLAB are you using? (this does not mean "academic", but something like "R2012b", or "R2017a"... that is what we need to know).
"reason why I looked for the documentation"
In order to know what your installed MATLAB does you should always use the installed documentation. The online documentation is interesting to read, but it bears no relationship to what you have installed.
답변 (1개)
Jan
2018년 6월 23일
편집: Jan
2018년 6월 23일
Since Matlab R2016b the elementwise multiplication uses "arithmetic expanding": The singleton dimensions are expanded to match the other operand. See e.g. Loren: arithmetic expanding
In older Matlab versions this was done by bsxfun :
a = [1 2 3]
b = (1:6)'
bsxfun(@times, a, b)
a .* b % Working since R2016b
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!