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

10 visualizzazioni (ultimi 30 giorni)
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 Commenti
Torsten
Torsten il 24 Mag 2021
Modificato: Torsten il 24 Mag 2021
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 il 24 Mag 2021
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!

Accedi per commentare.

Risposta accettata

G A
G A il 24 Mag 2021
Modificato: G A il 24 Mag 2021
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 Commenti
Peter Jan
Peter Jan il 24 Mag 2021
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 il 24 Mag 2021
You are welcome! I have just learned this behaviour myself - thank you too!

Accedi per commentare.

Più risposte (0)

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by