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 :,(
Matt J
Matt J 2013 年 1 月 9 日
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).

サインインしてコメントする。

質問済み:

2013 年 1 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by