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

10 次查看(过去 30 天)
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by