Count the frequency of a number in a series of numbers.

Hi,
I have created a random function to create randomly the numbers 1, 2 or 3. On another m-file I have ran this 100 times to see if it is uniformally distributed. I have done this by using a for loop. The function m-file is
function r = randit3;
r=randi(3,1);
and to test it works is
for a=1:100;
y=randit3;
end
However I want to count how many 1's, 2's and 3's come up. Please help.
I have tried plotting it on a graph and the best I can do is this.
for a=1:100;
y=randit3;
plot(a,y,'*')
hold on
end
Thank you

답변 (1개)

Paulo Silva
Paulo Silva 2011년 5월 8일
doc histc
example
a=[1 2 3 4 5 6 1 2 6 6 6];
[n,bin]=histc(a,1:6);
n is the frequency and bin is the number
example: 6 (bin(end)) appears 4 (n(end)) times
c = histc(A(:),unique(A))

댓글 수: 2

How do i input that into my code.
I have tried looking up the histc, however I am still a bit unsure.
Sorry, I am quite new to Matlab.
Thank you for your help.
Look at the asnwere given here to the same question: http://www.mathworks.com/matlabcentral/answers/7022-frequency-determination

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

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

질문:

2011년 5월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by