'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.
0 个评论
采纳的回答
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
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!