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

조회 수: 2,480(최근 30일)
Arnab Pal
Arnab Pal 2017년 8월 29일
댓글: Matthew Coile 2023년 2월 17일
a=[8 9 6 5 3], I want to know 5 is there or not.

채택된 답변

Guillaume
Guillaume 2017년 8월 29일
ismember(5, a)
  댓글 수: 2
Matthew Coile
Matthew Coile 2023년 2월 17일
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.

댓글을 달려면 로그인하십시오.

추가 답변(1개)

José-Luis
José-Luis 2017년 8월 29일
편집: José-Luis 2017년 8월 29일
sum(a==5) > 0
any(a==5)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by