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
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
Raminder1992
2011년 5월 8일
Oleg Komarov
2011년 5월 8일
Look at the asnwere given here to the same question: http://www.mathworks.com/matlabcentral/answers/7022-frequency-determination
카테고리
도움말 센터 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!