Error using == Matrix dimensions must agree.

2 vues (au cours des 30 derniers jours)
Riya Bothara
Riya Bothara le 3 Fév 2019
Rouvert : Walter Roberson le 3 Fév 2019
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
  2 commentaires
Riya Bothara
Riya Bothara le 3 Fév 2019
expression is same but the different error is occur.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 3 Fév 2019
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.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by