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

2 Ansichten (letzte 30 Tage)
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 Kommentar
Stephen23
Stephen23 am 17 Sep. 2017
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)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by