Count the index of the array

조회 수: 12 (최근 30일)
Mekala balaji
Mekala balaji 2014년 12월 20일
댓글: madhan ravi 2018년 12월 3일
Hi, I have a array like below: [0 0 0 0 0 0 0 0 0 10 0 0 0 0 15 0 17]
I want count how many numbers >0 in the array (like in this case count is 3 (because 10,15,&17). Can some please help me how to count this in matlab. Thanks in advance

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 20일
If your array doesn't contain negative numbers
a=[0 0 0 0 0 0 0 0 0 10 0 0 0 0 15 0 17]
out=nnz(a)
  댓글 수: 2
Shoaibur Rahman
Shoaibur Rahman 2014년 12월 20일
nnz will count the number of all non-zero elements in the array, including negatives. So, this function would be a better choice if you want to do so.
Mekala balaji
Mekala balaji 2014년 12월 20일
Great Thank you sir

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Shoaibur Rahman
Shoaibur Rahman 2014년 12월 20일
A=[0 0 0 0 0 0 0 0 0 10 0 0 0 0 15 0 17];
sum(A>0)

Javaid Iqbal
Javaid Iqbal 2018년 12월 3일
n=numel(A);
  댓글 수: 1
madhan ravi
madhan ravi 2018년 12월 3일
no this would give you total number of elements in the array

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by