How to check a number is in a array or not?

2 756 vues (au cours des 30 derniers jours)
Arnab Pal
Arnab Pal le 29 Août 2017
Commenté : Matthew Coile le 17 Fév 2023
a=[8 9 6 5 3], I want to know 5 is there or not.

Réponse acceptée

Guillaume
Guillaume le 29 Août 2017
ismember(5, a)
  2 commentaires
Putri Basenda Tarigan
Putri Basenda Tarigan le 16 Nov 2020
Excuse me Sir,
For the same problem, if we don't know that the number is 5, how to code to get that the number is 5?
Matthew Coile
Matthew Coile le 17 Fév 2023
Putri, you can just as easily use a variable. That is, ismember(x,a) would work as well, where the value of x is assigned earlier in the script.

Connectez-vous pour commenter.

Plus de réponses (1)

José-Luis
José-Luis le 29 Août 2017
Modifié(e) : José-Luis le 29 Août 2017
sum(a==5) > 0
any(a==5)

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by