How do I fit a gaussian to a bar plot and extract the variance of the gaussian?

21 Ansichten (letzte 30 Tage)
Because I'm not starting with raw histogram data, it's my understanding that histfit isn't apropriate for generating a gaussian fit. This has been my approach thus far:
x=[8,11,8,10,8,21,26,33,28,8,17,7,4,10,12];
y=1:15;
[fitobject,gof]=fit(y',x','gauss2');
figure
bar(y,x)
hold on
plot(fitobject,y,x)
but 1) it's unclear whether this is the best way to do this, and 2) I don't know how to extract the variance from this gaussian.
Thoughts? Thanks in advance!

Akzeptierte Antwort

Star Strider
Star Strider am 10 Sep. 2021
One approach —
x=[8,11,8,10,8,21,26,33,28,8,17,7,4,10,12];
y=1:15;
[fitobject,gof]=fit(y',x','gauss1');
figure
bar(y,x)
hold on
plot(fitobject,y,x)
fitobject
fitobject =
General model Gauss1: fitobject(x) = a1*exp(-((x-b1)/c1)^2) Coefficients (with 95% confidence bounds): a1 = 24.61 (17.1, 32.13) b1 = 7.828 (6.673, 8.983) c1 = 4.645 (2.954, 6.335)
Mean = fitobject.b1
Mean = 7.8278
Sigma = fitobject.c1
Sigma = 4.6447
Variance = fitobject.c1^2
Variance = 21.5732
Using ‘Gauss2’ is likely inappropriate here.
Experiment to get different results.
.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by