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

조회 수: 2,618 (최근 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
Putri Basenda Tarigan
Putri Basenda Tarigan 2020년 11월 16일
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 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)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by