Histogram with data frequency
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Jamal Nasir
am 7 Apr. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Histograms 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!