how to plot a histogram with distribution fitting?
Ältere Kommentare anzeigen
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 Kommentare
Star Strider
am 16 Aug. 2015
You’re probably looking for is histfit function. This is likely an ‘xor’ situation, where you can fit ‘battery’ or ‘battery-related’ but not both at the same time.
Feel free to experiment. It’s highly unlikely, but I could be wrong!
Amr Hashem
am 16 Aug. 2015
Bearbeitet: Amr Hashem
am 29 Okt. 2015
Image Analyst
am 16 Aug. 2015
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
am 17 Aug. 2015
Bearbeitet: Amr Hashem
am 17 Aug. 2015
Antworten (2)
Image Analyst
am 17 Aug. 2015
0 Stimmen
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
am 17 Aug. 2015
0 Stimmen
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 Kommentare
Amr Hashem
am 17 Aug. 2015
Bearbeitet: Amr Hashem
am 18 Aug. 2015
Zhang zhengnan
am 30 Jan. 2016
Bearbeitet: Zhang zhengnan
am 30 Jan. 2016
Thank you for your answer.Can you attach code about 'smooth the histogram with a Savitzky-Golay filter'?
Kategorien
Mehr zu Histograms finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


