Count the frequency of a number in a series of numbers.
4 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Paulo Silva
on 8 May 2011
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 Comments
Oleg Komarov
on 8 May 2011
Look at the asnwere given here to the same question: http://www.mathworks.com/matlabcentral/answers/7022-frequency-determination
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!