Count the frequency of a number in a series of numbers.
Mostrar comentarios más antiguos
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
Respuestas (1)
Paulo Silva
el 8 de Mayo de 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 comentarios
Raminder1992
el 8 de Mayo de 2011
Oleg Komarov
el 8 de Mayo de 2011
Look at the asnwere given here to the same question: http://www.mathworks.com/matlabcentral/answers/7022-frequency-determination
Categorías
Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!