Can I count the number of integers in an index and store it in a variable?
조회 수: 2 (최근 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
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)
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!