i want to count the frequency of occurrence of no 5 in the above vector .Is there any matlab function to count the frequency of occurrence of a particular number?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
sai kamal sreeja veepuri
am 9 Feb. 2015
Bearbeitet: per isakson
am 9 Feb. 2015
l=randi(10,1,20)
l =
Columns 1 through 9
10 8 2 6 2 8 6 6 8
Columns 10 through 18
10 9 5 2 4 5 10 7 9
Columns 19 through 20
8 7
i want to count the frequency of occurrence of no 5 in the above vector .Is there any matlab function to count the frequency of occurrence of a particular number?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 9 Feb. 2015
There are probably several ways of doing this, at least one involving the accumarray function. This one simply uses the hist function:
l=randi(10,1,20); % Data
Ul = unique(l); % Use For Bin Centres
[Cts, Ctrs] = hist(l, Ul); % Find Counts For Each Bin
Cts5 = Cts(Ctrs == 5); % Get Counts For Bin Value = 5
0 Kommentare
Weitere Antworten (1)
per isakson
am 9 Feb. 2015
Bearbeitet: per isakson
am 9 Feb. 2015
If the numbers are whole numbers and you want the "frequency" of one specific number then here is another way
>> L = randi(10,1,24);
>> sum( L==2 )/length(L)
ans =
0.2500
or maybe replace
sum( L==2 )/length(L)
by
sum( double( L==2 ) )/length(L)
btw: Lower case "L" is not a good name of a variable.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Elementary Math finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!