Finding the vertical offset of a gaussian fit

26 visualizaciones (últimos 30 días)
Ahmed Abdulla
Ahmed Abdulla el 28 de Jul. de 2021
Comentada: Stefan Rick el 19 de Jun. de 2023
I apologize for posting this question again, as I believe I miss presented my question earlier.
I have the following data points as shown in the picture, and I am in the quest to obtain the vertical offset (v0) for the best gaussian fit to my data point. Equation for gaussian fit: gaus = amp*exp(-(((x-mu).^2)/(2*sig.^2)))+ v0.
I currently have the datasets x and y and I am stuck at that, any help is appreciated and sorry for posting this again
  3 comentarios
Matt J
Matt J el 28 de Jul. de 2021
Editada: Matt J el 28 de Jul. de 2021
sorry for posting this again
Indeed, you Accepted an answer to the same question here:
Why do you need a different answer now?
Adam Danz
Adam Danz el 29 de Jul. de 2021
Also, the previous answer you accepted and then unaccepted also includes a vertical offset term and even lists the fit parameter values in the axes title.
You also copied the guassian equation from the previous answer into your current question above. I don't see how this question differs from the previous question.

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 28 de Jul. de 2021
Editada: Matt J el 28 de Jul. de 2021
This File Exchange routine does gaussian+constant fitting:
mu=5;
sig=2.3;
amp=4;
v0=1.7;
x=linspace(0,10,100);
y=amp*exp(-(((x-mu).^2)/(2*sig.^2)))+ v0;
y=y+randn(size(y))*0.1;
p=gaussfitn(x(:),y(:));
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
[v0,amp,mu,var]=p{:}, sig=sqrt(var)
v0 = 1.6697
amp = 4.0421
mu = 4.9868
var = 5.4130
sig = 2.3266
yfit=v0+amp*exp(-(((x-mu).^2)/(2*var)));
plot(x,y,'o',x,yfit)
  2 comentarios
Ahmed Abdulla
Ahmed Abdulla el 29 de Jul. de 2021
Thank you very much this is perfect :)
Stefan Rick
Stefan Rick el 19 de Jun. de 2023
I try to test gaussfitn with my own data and get the error:
"Error using gaussfitn
Expected zdata to be an array with number of elements equal to 1."
for
p=gaussfitn(1:645,yData)
Anyone find the mistake?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Curve Fitting Toolbox en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by