# How can I fit a Gaussian to data that only forms the peak

조회 수: 25(최근 30일)
Tristan Bras 18 Sep 2019
댓글: Tristan Bras 18 Sep 2019
I have some measurement data that shows a dip in the middle.
I'm trying to fit a Gaussian to that dip to characterize the width and height.
Right now I'm cutting my data down to the dip and trying to fit a gaussian with the following code:
gauss = 'a.*exp(-((x-b)./c).^2)+d';
f = fit(cutV,data,gauss);
coeffs = coeffvalues(f);
FWHM = coeffs(3)*2*sqrt(2*log(2));
height = coeffs(1);
figure;
subplot(2,1,1)
plot(cutV,data)
subplot(2,1,2)
plot(f,cutV,data);
While this does fit a Gaussian, it does so very poorly.
Instead of fitting the peak of the gaussian to the curve I have, it tries to fit the whole Gaussian function to the tiny dip I have.
How do I make the fit function only fit the peak of the Gaussian to my data?

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

### 채택된 답변

Johannes Fischer 18 Sep 2019

#### 댓글 수: 1

Tristan Bras 18 Sep 2019
Thank you! Scaling the data first did the trick.

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

R2018a

### Community Treasure Hunt

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

Start Hunting!

Translated by