Extracting data from a gaussian
조회 수: 16 (최근 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
채택된 답변
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
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 Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!