Can I count the number of integers in an index and store it in a variable?

1 次查看(过去 30 天)
index = find([X] == 1)
If I have an array X and I use index to find the where the value 1 is in the array and it gives me the following output that there are 2 places where the number 1 is found at spot [3;25]
index =
3
25
Can I store the value 2 in a variable that it found 2 integers?
  1 个评论
Stephen23
Stephen23 2017-9-17
The find is not required (logical indexing is often much more efficient than using find) The square brackets are also not needed.
nnz(X==1)

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2017-9-16
Yes.
Xeq1 = numel(index);
This is how I would do it.

更多回答(0 个)

类别

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