Error using vertcat Dimensions of arrays being concatenated are not consistent.

10 ビュー (過去 30 日間)
Peter Jan
Peter Jan 2021 年 5 月 24 日
コメント済み: Peter Jan 2021 年 5 月 24 日
I have copied three matrices generated in Python to Matlab.
Matlab however tells me that for the Y0 matrix:
Error using vertcat Dimensions of arrays being concatenated are not consistent.
Error in Y0Y1Y2 (line 3) Y0=[[0.-20.j , 0. +0.j , 0. +0.j , 0. +0.j ],
If I delete Y0, Y1 and Y2 are fine. There is just something wrong with Y0, but I can't understand what.
Y0=[[0.-20.j , 0. +0.j , 0. +0.j , 0. +0.j ],
[0. +0.j , 0.-12.j , 0. +2.j , 0. +0.j ],
[0. +0.j , 0. +2.j , 0.-12.j , 0. +0.j ],
[0. +0.j , 0. +0.j , 0. +0.j , 0. -2.85714286j]]
Y1=[[0.-12.68115942j, 0. +8.33333333j, 0. +0.j , 0. +0.j ],
[0. +8.33333333j, 0.-15.j , 0. +6.66666667j, 0. +0.j ],
[0. +0.j , 0. +6.66666667j, 0.-15.j , 0. +8.33333333j],
[0. +0.j , 0. +0.j , 0. +8.33333333j, 0.-12.5j ]]
Y2=[[0.-16.02564103j, 0. +8.33333333j, 0. +0.j , 0. +0.j ],
[0. +8.33333333j, 0.-15.j , 0. +6.66666667j, 0. +0.j ],
[0. +0.j , 0. +6.66666667j, 0.-15.j , 0. +8.33333333j],
[0. +0.j , 0. +0.j , 0. +8.33333333j, 0.-15.47619048j]]
  4 件のコメント
Torsten
Torsten 2021 年 5 月 24 日
編集済み: Torsten 2021 年 5 月 24 日
Ok, then do the necessary changes to Y0, Y1 and Y2 I explained in my answer:
Remove the [] around the vectors, replace the , at the end of each line by ; ... and write a+1i*b for the complex numbers instead of a+bj (without spaces, as G A observed).
Peter Jan
Peter Jan 2021 年 5 月 24 日
It actually works with the [] and the , as it was, it was just the spaces between the numbers where Matlab uses , and spaces which was the problem. But thank you very much for your time!

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

採用された回答

G A
G A 2021 年 5 月 24 日
編集済み: G A 2021 年 5 月 24 日
It seams that if there is a space between the real and imaginary parts of the number, Matlab considers it as two different numbers. So rewrite your matrices without spaces.
% with spaces
[0.-20.j , 0. +0.j , 0. +0.j , 0. +0.j ]
ans =
Column 1
0 - 20i
Column 2
0 + 0i
Column 3
0 + 0i
Column 4
0 + 0i
Column 5
0 + 0i
Column 6
0 + 0i
Column 7
0 + 0i
% without spaces
[0.-20.j , 0.+0.j , 0.+0.j , 0.+0.j ]
ans =
Column 1
0 - 20i
Column 2
0 + 0i
Column 3
0 + 0i
Column 4
0 + 0i
  2 件のコメント
Peter Jan
Peter Jan 2021 年 5 月 24 日
Thank you very much! I didn't thought is will mix the use of spaces and commas. So actually my definition of Y1 and Y2 was also wrong. Thanks again.
G A
G A 2021 年 5 月 24 日
You are welcome! I have just learned this behaviour myself - thank you too!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by