Extracting data from a gaussian

32 vues (au cours des 30 derniers jours)
Justin Skaggs
Justin Skaggs le 24 Juil 2019
Commenté : Walter Roberson le 30 Juil 2019
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 commentaires
Walter Roberson
Walter Roberson le 24 Juil 2019
Examine
methods(f1)
Justin Skaggs
Justin Skaggs le 24 Juil 2019
Modifié(e) : Justin Skaggs le 24 Juil 2019
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

Connectez-vous pour commenter.

Réponse acceptée

Jalaj Gambhir
Jalaj Gambhir le 30 Juil 2019
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 commentaires
Justin Skaggs
Justin Skaggs le 30 Juil 2019
Thank you so much! That worked perfectly!
Walter Roberson
Walter Roberson le 30 Juil 2019
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by