Effacer les filtres
Effacer les filtres

Finding a needle in a matrix

1 vue (au cours des 30 derniers jours)
012786534
012786534 le 12 Avr 2017
Commenté : 012786534 le 12 Avr 2017
Hello,
Let's say I have a 10 x 10 matrix filled with numbers (10 X 10 double) which can only be 1, 2 or 3. I need a code that returns an error if there's any other number in there, like say a 4 or an 8. I would have thought that:
if Y ~=1|Y ~=2|Y ~=3
disp('error')
return,
end
would work but it always returns an error message. Any ideas?
Thank you

Réponse acceptée

the cyclist
the cyclist le 12 Avr 2017
Modifié(e) : the cyclist le 12 Avr 2017
if not(all(ismember(Y(:),[1 2 3])))
disp('error')
end
  1 commentaire
012786534
012786534 le 12 Avr 2017
That's great! Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing 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