Accessing Fit Coefficients from Curve Fitting
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 setHello, 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 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 curve fitting, gaussian distribution MATLAB Answers — New Questions