Borrar filtros
Borrar filtros

".*" does not work need help

1 visualización (últimos 30 días)
Yildirim Kocoglu
Yildirim Kocoglu el 23 de Jun. de 2018
Editada: Jan el 23 de Jun. de 2018
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 comentario
Stephen23
Stephen23 el 23 de Jun. de 2018
Editada: Stephen23 el 23 de Jun. de 2018
@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.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 23 de Jun. de 2018
Editada: Jan el 23 de Jun. de 2018
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

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by