Error using == Matrix dimensions must agree.
2 次查看(过去 30 天)
显示 更早的评论
if(color ==[255 255 255 ] || color==[0 0 0] || color==[255 0 0] || color==[205 133 63] || color==[101 67 33] || color==[0 134 139] )
end
回答(1 个)
Walter Roberson
2019-2-3
if color is a 1 x 1 x 3 array instead of a 1 x 3 array, then the == would fail in R2016a and earlier.
If color is a M x N x 3 array then comparing to a 1 x 3 array would fail in R2016a or earlier. In R2016b or later, it would only succed if N were 3 , so that you were comparing a M x 3 x 3 array to a 1 x 3 array, in which case it would be comparing rows to the given color value.
If your color array did happen to be the right size to match against a 1 x 3 array, or if you were to compare M x N x 3 to reshape([255 255 255], 1, 1, 3) then the == would not fail. However in such a case, the || would fail. || can only be used to "or" together conditions if each of the conditions is scalar.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!