Borrar filtros
Borrar filtros

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

35 visualizaciones (últimos 30 días)
Ahmad Hasnain
Ahmad Hasnain el 21 de Sept. de 2018
Respondida: Ahmad Hasnain el 21 de Sept. de 2018
*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?

Respuesta aceptada

Adam Danz
Adam Danz el 21 de Sept. de 2018
if ismember(alpha, A)
or
if any(A == alpha)

Más respuestas (1)

Ahmad Hasnain
Ahmad Hasnain el 21 de Sept. de 2018
Thanks

Categorías

Más información sobre NaNs en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by