Extracting data from a gaussian

25 次查看(过去 30 天)
Hello everyone,
I am facing troubles trying to extract data from a gaussian curve. I can extract the information I need from my raw data (max y, corresponding x value, and FWHM) but I am not sure how to get a gaussian fit and extract the same data from it.
I am able to create a gaussian using fit
f1=fit(Mwavelength(:,t),MPL(:,t),'gauss2');
but cannot get any information out of my gaussian curve, only plot it since the variable f1 comes out to be a 1 x 1 cfit.
Any help would be greatly appreciated!
N=(196x7 string) % Each entry corresponds to the title of a text file, which contains two columns of data.
for t = 1:7
for k = 1:196
spectra = importdata(N(k,t)); % Import the data from the .txt file
%I want to get a gaussian fit of the spectra here, and then gather the wavelength (x axis values) and PL (yaxis values) from that.
wavelength(:,k) = spectra(:,1); % my x-axis
PL(:,k) = spectra(:,2); % my y-axis
[M,I] = max(PL(:,k));
X = wavelength(I,k);
Peaks(k,t) = M; % Creates matrix 'Peaks' with the max peak for all pixels in the 14x14 data collection area
Position(k,t) = X; % Creates matrix 'Position' with the corresponding x value at the peak.
end
Mwavelength(:,t) = mean(wavelength,2);
MPL(:,t) = mean(PL,2);
end
  2 个评论
Justin Skaggs
Justin Skaggs 2019-7-24
编辑:Justin Skaggs 2019-7-24
Hi Walter,
Thank you for commenting.
I inputed that and I am not sure what to do with this.
>> methods(f1)
Methods for class cfit:
argnames coeffvalues feval integrate plot setoptions
category confint fitoptions islinear predint type
cfit dependnames formula numargs probnames
coeffnames differentiate indepnames numcoeffs probvalues

请先登录,再进行评论。

采纳的回答

Jalaj Gambhir
Jalaj Gambhir 2019-7-30
Hi,
As you saw,
methods(f1)
returns the plausible functions that can be used with the cfit class object f1. You can check the documentation to know more about them.
coeffvalues(f1)
returns the coefficient values for the function
fun(x) = a1*exp(-((x-b1)/c1)^2) + a2*exp(-((x-b2)/c2)^2)
as a row vector. You can use these coefficients to recreate the estimated curve and extracting the required information from it.
For example:
function estimated_y = gaussian(x,coeff_vector)
estimated_y = coeff_vector (1)*exp(-((x- coeff_vector (2))/ coeff_vector (3)).^2) + coeff_vector (4)*exp(-((x- coeff_vector (5))/ coeff_vector (6)).^2);
end
The above function takes as input the x values and the coefficient values of the curve and returns the vector of estimated Y values from it. You can use findpeaks and max functions to know the maximum x and y values from the curve. Similarly, after knowing the curve parameters you can estimate other required information. For FWHM, you can refer here.
  2 个评论
Justin Skaggs
Justin Skaggs 2019-7-30
Thank you so much! That worked perfectly!
Walter Roberson
Walter Roberson 2019-7-30
Also if what you want to do is predict y values from x according to the coefficients modelled, then f1(x) will do that, where f1 is the result of the fit operation.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by