Creating a frequency table
显示 更早的评论
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 个评论
Azzi Abdelmalek
2013-5-31
This is not clear
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.
采纳的回答
更多回答(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];
Azzi Abdelmalek
2013-5-31
x=[1 1 2 2 1 2 ]
y=[x 5]
out=tabulate(y)
out(end,:)=[]
6 个评论
googo
2013-5-31
Azzi Abdelmalek
2013-5-31
You said between 1 and 4
Azzi Abdelmalek
2013-5-31
编辑:Azzi Abdelmalek
2013-5-31
If there is no 4 in your list, tabulate will not show 4 0 0 like you said, To resolve the problem,I've added 5 and removed its result
Iman Ansari
2013-5-31
x=[1 1 2 2 1 2 ];
[0:4 ;histc(x,0:4)]'
Azzi Abdelmalek
2013-5-31
Iman , make it as an answer
类别
在 帮助中心 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!