Creating a frequency table

조회 수: 11 (최근 30일)
googo
googo 2013년 5월 31일
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
googo
googo 2013년 5월 31일
편집: googo 2013년 5월 31일
Ok, sorry.
For example : [4 3 2 2 4 3 3] {only numbers between 0-4}
I'm looking for a function that will return a frequency vector :
0
0
2
3
4
Image Analyst
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
Azzi Abdelmalek 2013년 5월 31일
a=arrayfun(@(z) sum(ismember(x,z)),0:4)'
out=[(0:4)' a 100*a/numel(x)]

추가 답변 (2개)

Andrei Bobrov
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
Azzi Abdelmalek 2013년 5월 31일
x=[1 1 2 2 1 2 ]
y=[x 5]
out=tabulate(y)
out(end,:)=[]
  댓글 수: 6
Iman Ansari
Iman Ansari 2013년 5월 31일
x=[1 1 2 2 1 2 ];
[0:4 ;histc(x,0:4)]'
Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 31일
Iman , make it as an answer

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

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by