Histogram with data frequency
25 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I need to make a histogram that each of the data have their own frequency
say:
X=[ 4 3 1 12 15 3 8 15 13 20 4 12 15 16 16 2 2 15 18 4 ]
is the data and
Y=[ 2 1 1 1 2 2 1 1 1 1 1 2 2 2 1 2 1 2 1 2 ]
is the frequency of each of the data
and I need to bin these data into 20 bins, such as
binEdges = linspace(0, 1, 20+1)
a normal histogram of X would show the frequency of "4" as 3 because there are 3 of them in the X. What I want to achieve is to have a histogram that would show a frequency of 5 for "4" because there are two "4" with Y frequency of 2 and one "4" with Y frequency of 1. Same goes with the rest. How to code this logic?
Thanks,
Fadhil
0 commentaires
Réponses (2)
Jamal Nasir
le 7 Avr 2020
%%%%%%% you can use this code %%%%%%%%%%%
a=unique(x);
b=length(a);
for i=1:b
c(i)=sum(y(x==a(i)));
end
bar(c)
%%%%%%%%% jamal %%%%%%%%%%%
0 commentaires
Voir également
Catégories
En savoir plus sur Histograms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!