Plus as concatenate for numeric vectors?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I've been using Matlab for years and I've never seen this before, is it new? It was hard to debug this since it's pretty subtle
size([ones(1,10) +ones(1,10)])
Apparently if you don't put a space after the plus sign -- and there is a space before it -- then + concatenates instead of adding. There's nothing in the documentation for + about concatenating numeric arrays. I don't really have a question, this just seems really confusing as a feature.
1 comentario
Respuesta aceptada
dpb
el 17 de Nov. de 2025
Editada: dpb
el 17 de Nov. de 2025
No it's not new. In that expression the plus sign is interpreted as the sign of the value, not as an arithmetic operator.
It's no different than
[1 +1]
or
[1 -1]
the latter of which wouldn't surprise you -- in fact, you'd be very disconcerted if it produced the same as
[1-1]
or
[1 - 1]
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!