How to use for-end loops to count number of occurrences of an array?

조회 수: 1 (최근 30일)
David
David 2014년 11월 29일
댓글: Stephen23 2014년 12월 1일
I want to know how can I count the number of occurrences of one array by using for-end loops. Pls help me.
  댓글 수: 1
Stephen23
Stephen23 2014년 12월 1일
"count the number of occurrences of one array" doesn't make much sense, as an array only exists once in MATLAB's workspace. Do you mean to count the occurrences of element values within an array?

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

답변 (2개)

Zack Bayhan
Zack Bayhan 2014년 11월 29일
So could you do something like this
count=0;
for i=1:10
if i==1
count=count+1
end
end

Image Analyst
Image Analyst 2014년 11월 29일
"the number of occurrences of one array"??? Why would an array occur more than once ? Maybe you mean number instead of array . In that case, just take the histogram to count how many times each number occurs in an array. You can also use histc:
edges = unique(yourArray(:));
counts = histc(yourArray(:), edges);

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by