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

 Akzeptierte Antwort

Guillaume
Guillaume am 29 Aug. 2017

15 Stimmen

ismember(5, a)

2 Kommentare

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 am 17 Feb. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

José-Luis
José-Luis am 29 Aug. 2017
Bearbeitet: José-Luis am 29 Aug. 2017

3 Stimmen

sum(a==5) > 0
any(a==5)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by