'Dimensions of arrays being concatenated are not consistent' when using isequal

1 回表示 (過去 30 日間)
[updated1, dist1] = googleMaps(map1, dir1);
[updated1_soln, dist1_soln] = googleMaps_soln(map1, dir1);
t10 = isequal([updated1, dist1], [updated1_soln, dist1_soln])
Where running t10 prints the error:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in hw07 (line 107)
t10 = isequal([updated1, dist1], [updated1_soln, dist1_soln])
I am not trying to concatenate, why is it printing that?
I'll add the variables (as a disclaimer, they won't make much sense, I'm running this to compare answers for a hw assignment)
Running an == comparison gives:
>> dist1 == dist1_soln
ans =
logical
1
>> updated1 == updated1_soln
ans =
5×5 logical array
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
>>
And the variables are:
updated1
val =
' '
' '
'x## '
' # '
' o '
updated1_soln
val =
' '
' '
'x## '
' # '
' o '
dist1 and dist1_soln are both 4 1x1 doubles. I don't understand why isequal is doing this though, I've used it for things like this often, without getting that error.

採用された回答

the cyclist
the cyclist 2019 年 10 月 5 日
編集済み: the cyclist 2019 年 10 月 5 日
What sizes are updated1 and dist1 (and the other pair)?
[updated1, dist1]
  3 件のコメント
the cyclist
the cyclist 2019 年 10 月 5 日
The syntax
[updated1, dist1]
inside of the isequal command is trying to concatenate a 5x5 logical array with a 4x1 double (before it checks with the other argument for equality). That will cause an error. That syntax for the isequal command is not comparing
updated1 == updated1_soln
and
dist1 == dist1_soln
"in parallel", as you seem to intend.
The reason that your other case works is that one can horizontally concatenate
'Player 1 wins!'
and
[11 6 8 4 13 9 10 3 12 7 5 2]
into a character vector.
Instead, you'll need to do something like
isequal(updated1, updated1_soln) && isequal(dist1, dist1_soln)
Julia Sequerth
Julia Sequerth 2019 年 10 月 5 日
I guess I've just been lucky that it concatenated until this point, I'll be sure to separate them in the future. Thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by