How to use for-end loops to count number of occurrences of an array?
1 回表示 (過去 30 日間)
古いコメントを表示
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
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
2014 年 11 月 29 日
So could you do something like this
count=0;
for i=1:10
if i==1
count=count+1
end
end
0 件のコメント
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);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!