Why does adding a space give vertcat error?

1 visualización (últimos 30 días)
Ashish Uniyal
Ashish Uniyal el 10 de Oct. de 2021
Editada: G A el 10 de Oct. de 2021
Although this works as expected
[1;1+1]
ans = 2×1
1 2
Inserting a space gives vertcat error for some reason
[1;1 +1]
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Why does this occur?

Respuesta aceptada

G A
G A el 10 de Oct. de 2021
with a space, [1;1 +1] is interpreted as [1;1, +1]. [1;(1 +1)] will be OK.
  2 comentarios
Ashish Uniyal
Ashish Uniyal el 10 de Oct. de 2021
Ah got it, thanks a lot! Although it's a bit unexpected with an operator sitting there.
G A
G A el 10 de Oct. de 2021
Editada: G A el 10 de Oct. de 2021
I found that
[1 + 1; 1 + 1]
ans =
2
2
[1 +1; 1 +1]
ans =
1 1
1 1
[1+1; 1+1]
ans =
2
2
[1+ 1; 1+ 1]
ans =
2
2
the same behaviour if the second number is imaginary as 1i

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays 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