필터 지우기
필터 지우기

how to sum a group of gaussian distribution using "hist" ?

조회 수: 5 (최근 30일)
Amr Hashem
Amr Hashem 2015년 11월 4일
댓글: Image Analyst 2015년 11월 5일
I want to add five gaussian distributions at different points on x-axis
I try:
n=500;
H1 = normrnd(14,5,n,1); % generate random numbers of normal distribution at mu and sigma
H2 = 24+ normrnd(14,5,n,1); % start from 24
H3 = 48+ normrnd(14,5,n,1);
H4 = 72+ normrnd(14,5,n,1);
H5 = 96+ normrnd(14,5,n,1);
figure
hhh = [H1 H2 H3 H4 H5];
hist(hhh,130)
which produce a good figure as I need:
but I want to plot the total values of the intersected area. (I put a circle on them)
How I can sum them?

채택된 답변

the cyclist
the cyclist 2015년 11월 4일
편집: the cyclist 2015년 11월 4일
One simple possibility is to create one 2500x1 vector of the data rather than the 550x5 array you have, which is as simple as
hhh = [H1; H2; H3; H4; H5];
in place of
hhh = [H1 H2 H3 H4 H5];
If you do that, you will lose the distinct colors of the five histograms. But if you don't do it that way, you will have the problem of coloring the summed histograms, which gets tricky.
  댓글 수: 2
Amr Hashem
Amr Hashem 2015년 11월 4일
I used this code to change color for each:
hist(H,34)
h = findobj(gca,'Type','patch');
set(h,'FaceColor','b','EdgeColor','w')
but it changed all by the last color
Image Analyst
Image Analyst 2015년 11월 5일
But with this method, you don't know which bins are in the "overlap/intersection" region and which are not. Determining "total values of the intersected area" was a requirement/request.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 11월 4일
Try it like this, to sum the bins where both histograms are non-zero:
n=500;
H1 = normrnd(14,5,n,1); % generate random numbers of normal distribution at mu and sigma
H2 = 24+ normrnd(14,5,n,1); % start from 24
H3 = 48+ normrnd(14,5,n,1);
H4 = 72+ normrnd(14,5,n,1);
H5 = 96+ normrnd(14,5,n,1);
figure
hhh = [H1 H2 H3 H4 H5];
hist(hhh,130)
edges = -20:140;
counts1 = histc(H1, edges);
counts2 = histc(H2, edges)
counts3 = histc(H3, edges);
counts4 = histc(H4, edges);
counts5 = histc(H5, edges);
% Get indexes of first overlap region.
mask = counts1>0 & counts2>0;
% Sum both histograms in that area.
sum1 = sum(counts1(mask)) + sum(counts2(mask))
% Get indexes of second overlap region.
mask = counts2>0 & counts3>0;
% Sum both histograms in that area.
sum2 = sum(counts2(mask)) + sum(counts3(mask))
% Get indexes of third overlap region.
mask = counts3>0 & counts4>0;
% Sum both histograms in that area.
sum3 = sum(counts3(mask)) + sum(counts4(mask))
% Get indexes of fourth overlap region.
mask = counts4>0 & counts5>0;
% Sum both histograms in that area.
sum4 = sum(counts4(mask)) + sum(counts5(mask))
  댓글 수: 2
Amr Hashem
Amr Hashem 2015년 11월 4일
편집: Amr Hashem 2015년 11월 4일
it gives me the values of overlaped regions but nothing change in the figure (didn't plot them on the graph )
Image Analyst
Image Analyst 2015년 11월 5일
I thought you could just use text() if you wanted some label on there, like
message = sprintf('The sum here = %d', sum1);
text(x,y,message);

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by