How to compare a number with all the values of a vector?

조회 수: 29 (최근 30일)
Ahmad Hasnain
Ahmad Hasnain 2018년 9월 21일
답변: Ahmad Hasnain 2018년 9월 21일
*I have the following function: *
function Z = imp (alpha) % alpha is a scalar
A = [10 20 30 40 50 60 70] % I have this vector
if
alpha = A *%any value of A*
true *% If a value of alpha is equal to any value of A the statement is true otherwise it is false*
else
false
end
I want to compare alpha with all the values of vector A. If alpha is equal to any one value of A, then the statement is true. How do I do this in code?

채택된 답변

Adam Danz
Adam Danz 2018년 9월 21일
if ismember(alpha, A)
or
if any(A == alpha)

추가 답변 (1개)

Ahmad Hasnain
Ahmad Hasnain 2018년 9월 21일
Thanks

카테고리

Help CenterFile Exchange에서 Big Data Processing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by