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

2,570 次查看(过去 30 天)
a=[8 9 6 5 3], I want to know 5 is there or not.

采纳的回答

Guillaume
Guillaume 2017-8-29
  2 个评论
Putri Basenda Tarigan
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 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by