Why does adding a space give vertcat error?

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?

 採用された回答

G A
G A 2021 年 10 月 10 日

1 投票

with a space, [1;1 +1] is interpreted as [1;1, +1]. [1;(1 +1)] will be OK.

2 件のコメント

Ashish Uniyal
Ashish Uniyal 2021 年 10 月 10 日
Ah got it, thanks a lot! Although it's a bit unexpected with an operator sitting there.
G A
G A 2021 年 10 月 10 日
編集済み: G A 2021 年 10 月 10 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

質問済み:

2021 年 10 月 10 日

編集済み:

G A
2021 年 10 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by