フィルターのクリア

Plotting Two Gaussians on One Histogram

5 ビュー (過去 30 日間)
Michael
Michael 2013 年 9 月 17 日
I'd like to be able to make a histogram which has two distinct gaussian curves.. like a camel with two humps on its back. Preferably creating the gaussians from randn() would be ideal.
I think the question is based on generating the gaussian and adding the index/bins to the vector/data in some way. So, if I've phrased this correctly: How do I tack on the indices to the gaussians and overlap them (and I mean like literal addition by that)?
The picture quality is kinda bad but this:
is what I'm going for. Except I'd like it to be binned like a histogram.. perhaps using bar would be more effective?? My knowledge is low in this area and I appreciate all the help you can offer!
Thanks in advance, M.A.B.

採用された回答

Laurent
Laurent 2013 年 9 月 17 日
Hi,
you can create the two shifted histograms with randn.
gauss1=randn(100000,1)/2+1; %create gaussian around +1
gauss2=randn(100000,1)/2-1; %create gaussian around -1
gausssum=[gauss1;gauss2]; %combine values
The histogram can than be made with 'hist'
[N,X]=hist(gaussum,100);
plot(X,N);
Is this what you were looking for?
  1 件のコメント
Michael
Michael 2013 年 9 月 17 日
Perfect! Thank you. I was trying something like this on saturday... I should review it to see where I went wrong. Thank you very much for your input!

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2013 年 9 月 17 日
Basic idea; I've got to run so you can fill in the inbetween by adding the appropriate bin counts and drawing the line on top or however you want to do it...
a=randn(200,1); % generate a normal sample mean 0, var 1
[n1,x1]=hist(1+a*0.25); [n2,x2]=hist(0.25*a-1);
bar(x1, n1,0.4), hold on, bar(x2,n2,0.4), hold off
Adjust the multiplier on the variance as per your data...
  1 件のコメント
Michael
Michael 2013 年 9 月 17 日
I also like this method. Thank you for your input as well! I appreciate your time.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by