Accessing Fit Coefficients from Curve Fitting

22 visualizaciones (últimos 30 días)
Elias
Elias el 9 de Jun. de 2024
Comentada: Elias el 10 de Jun. de 2024
Hello, I am attempting to generate a graph of the full width half max (FWHM) of multiple sets of data but want to first fit each dataset to a Gaussian. Currently, I am calculating the FWHM by indexing the first and last instances of the half-max value for each dataset, then graphing all of these values. This works alright; however, I would like to improve upon this by fitting each dataset to a Gaussian distribution and then use the calculated Gaussian coefficients from the fitting in order to find the FWHM, as this would be more accurate. I have been able to fit each dataset to a Gaussian using the fit() function. However, I have run into an issue where I seem to be unable to access the generated Gaussian coefficients, which are what I need in order to be able to recalculate the FWHM. Does anyone know how I might be able to access these coefficients or generate them in such a way that I would be able to access them? Below I have copied the portion of my code where I am fitting the data along with a screenshot of the particular math I am referring to using the Gaussian coefficients to calculate the FWHM. Thank you so much!
y_fit = data.'; % turns data into a variable for fit, transposes to column
l_y = length(y_fit); % generates a variable with the length of y_fit
x_fit = linspace(0,l_y,l_y).'; % creates a column variable simply for the x-axis
data_fit = fit(x_fit,y_fit,'gauss1'); % this creates a fitted data set

Respuesta aceptada

the cyclist
the cyclist el 9 de Jun. de 2024
data_fit is a cfit object. You can apply post-processsing steps to this object, as described in this documentation.
It sounds like you specifically need the coeffvalues function.
  1 comentario
Elias
Elias el 10 de Jun. de 2024
This is exactly what I need thank you so much for pointing me the right direction!

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by