Count the frequency of a number in a series of numbers.
Ältere Kommentare anzeigen
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
Antworten (1)
Paulo Silva
am 8 Mai 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 Kommentare
Raminder1992
am 8 Mai 2011
Oleg Komarov
am 8 Mai 2011
Look at the asnwere given here to the same question: http://www.mathworks.com/matlabcentral/answers/7022-frequency-determination
Kategorien
Mehr zu Data Distribution Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!