Creating a frequency table
7 ビュー (過去 30 日間)
古いコメントを表示
Hello,
suppose I have a vector in legnth of 100 that contains a number between 1-4 how can I make a frequncy vector using the data in the vector? I'd tryed the function tabulate but if there is no 4 or 3 for example it will not be in the table and I want it to be there just with the value 0.
Thank's!
3 件のコメント
Image Analyst
2013 年 5 月 31 日
編集済み: Image Analyst
2013 年 5 月 31 日
That's simply the histogram - I think - and you can use histc() or hist(). It's "I think" because I'm not sure why you say there are four 4's when I only see 2. The histogram would say there is two 4's in [4 3 2 2 4 3 3]. Perhaps you can explain your thought process around how you came up with four 4's.
採用された回答
Azzi Abdelmalek
2013 年 5 月 31 日
a=arrayfun(@(z) sum(ismember(x,z)),0:4)'
out=[(0:4)' a 100*a/numel(x)]
0 件のコメント
その他の回答 (2 件)
Andrei Bobrov
2013 年 5 月 31 日
x=[1 1 2 2 1 2 ];
a = histc(x(:),0:4);
out = [(0:4)', a, a/sum(a)*1e2];
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Discrete Data Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!