How to fit data to a Gaussian distribution

Hi there, I'm quite new of MatLab and thus I hope you'll be patient with me.
I need to fit a given distribution (an actual one I generated from subjects) to its theorical Gaussian and get the R square value.
The Model (Gaussian distribution) I use is: Y=Amplitude*exp(-0.5*((X-Mean)/SD)^2) Amplitude is the height of the centre of the distribution in Y units. Mean is the X value at the centre of the distribution. SD is a measure of the width of the distribution, in the same units as X.
Rules for initial values Parameter Initial value Rule Amplitude 1.0 *YMAX No constraint MEAN 1.0 *(Value of X at YMAX) No constraint SD 0.1 *(XMAX-XMIN) Must be > 0.0
I use to do that with GraphPad and SPSS but I'd like to be able to do that in MatLab too. I need some good soul to tel me, step by step, how to do that in MatLab.... Please

답변 (2개)

Matt J
Matt J 2013년 1월 9일
편집: Matt J 2013년 1월 9일

0 개 추천

Study the documentaion for FMINSEARCH and consider the following
fminsearch(@(p) norm( p(1).*exp(-0.5.*((X(:)-p(2))./p(3)).^2) -Y(:)), p0)

댓글 수: 3

Lorenzo
Lorenzo 2013년 1월 9일
Sorry but I don't get it :,(
Here's a simpler example where I fit the slope p(1) and intercept p(2) of a line:
>>x=0:.01:1;
y=2*x+1;
initialguess=[0,0];
>> [pfit,residual]=fminsearch(@(p) norm(p(1)*x+p(2)-y) , initialguess)
pfit =
2.0000 1.0000
residual =
2.1512e-04
In reality, you would use POLYFIT to fit a line or any other polynomial, of course. This was just an example.
Lorenzo
Lorenzo 2013년 1월 10일
Thanks, I'll try to see if I can make it working (as I said I am really neieve of MatLab).

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

카테고리

도움말 센터File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

질문:

2013년 1월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by