how to plot a histogram with distribution fitting?

조회 수: 3 (최근 30일)
Amr Hashem
Amr Hashem 2015년 8월 15일
편집: Zhang zhengnan 2016년 1월 30일
I want to plot a histogram with distribution fit.
I use this code:
z=[1,2,3,4,5];
l = [ 502 3341; 724 3502; 1310 3379; 2966 4001; 1915 3858];
figure;bar(l,'stacked')
set(gca,'xticklabel',z);
to plot a stacked fig.
but now I want to plot a histogram fig with distribution fit, - with my data - like this:
I use:
hist
but it didn't work ): , giving me an error "double"
how I can do this ?
  댓글 수: 4
Image Analyst
Image Analyst 2015년 8월 16일
Why are your counts and categories, and even the size of the dimensions of the badly-named "l" different all the time? I'm not even clear what you want. I see a Gaussian curve over a bar chart in both cases. What do you want? Do you want the bar stacked like when you used a 2D l instead of a 1-d l?
Amr Hashem
Amr Hashem 2015년 8월 17일
편집: Amr Hashem 2015년 8월 17일
sorry for the badly name "l" , I'll change it.
first "l" s is a stacked so [ 502 3341 ;... ], is equal to
second "l" s [ 3843;...].
and I want to plot a histogram and then draw over it a distribution fit curve.
like this but on my data:
or this
I try many functions:
hist
histogram
histfit
histc
but it didn't work, any idea please?

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

답변 (2개)

Image Analyst
Image Analyst 2015년 8월 17일
If you have no particular shape in mind, like the last plot above that you showed with the lumpy red curve, then you can use a Savitzky-Golay filter (demo attached). Attach the data for your last bar chart and I'll show you how with your actual data.

Image Analyst
Image Analyst 2015년 8월 17일
Alright, I did a full blown demo for you. I let you choose an image to read in, then get the histogram, then smooth the histogram with a Savitzky-Golay filter (which is like a sliding polynomial filter). See the attached code below this image that it creates:
  댓글 수: 2
Amr Hashem
Amr Hashem 2015년 8월 17일
편집: Amr Hashem 2015년 8월 18일
it seems that the image is not well attached
Zhang zhengnan
Zhang zhengnan 2016년 1월 30일
편집: Zhang zhengnan 2016년 1월 30일
Thank you for your answer.Can you attach code about 'smooth the histogram with a Savitzky-Golay filter'?

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

카테고리

Help CenterFile Exchange에서 Exploration and Visualization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by