필터 지우기
필터 지우기

Histogram with data frequency

조회 수: 23 (최근 30일)
Fadhil Ahmad Qamar
Fadhil Ahmad Qamar 2020년 4월 7일
답변: dpb 2020년 4월 7일
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

답변 (2개)

Jamal Nasir
Jamal Nasir 2020년 4월 7일
%%%%%%% 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 %%%%%%%%%%%

dpb
dpb 2020년 4월 7일
nc=accumarray(X.',Y.');
bar(1:numel(nc),nc)

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by