How do I get the error of a fitting function?

조회 수: 26 (최근 30일)
JJH
JJH 2019년 1월 14일
댓글: Star Strider 2019년 1월 16일
I've written a function that does a Lorentzian fit on a set of data. I want to calculate an error bar for the accuray of this fit with respect to the x coordinates (the parameter Wavelength). Is this a built in command or is it more difficult?
function [params, Wavelength, Intensity, wavpeak]=SpectrumPeakFitCSV(filename)
SpectrumData=csvread(filename);
Wavelength=SpectrumData(2:end-1,1);
Intensity=SpectrumData(2:end-1,2);
Max = max(Intensity);
peak = find(Intensity==Max(1));
wavpeak = Wavelength(peak(1));
fun=@(x,Wav)Lorentzian(x(1),x(2),x(3),Wav)+x(4);
dark=Intensity(1);
opts = optimset('Display','off');
x=lsqcurvefit(fun,[Max(1),1,wavpeak,dark],Wavelength,Intensity,[0.5*Max(1) 0 wavpeak-0.2 0.9*dark],[2*Max(1) 3 wavpeak+0.2 1.5*dark],opts);
params=x; %scale, width, centre, dark
end

채택된 답변

Star Strider
Star Strider 2019년 1월 14일
If I understand correctly what you want to do, the Statistics and Machine Learning Toolbox function nlpredci (link) is likely what you are looking for. Use the ‘jacobian’ output (last output) from lsqcurvefit with it.
  댓글 수: 5
Janna Hinchliff
Janna Hinchliff 2019년 1월 16일
Thanks, nlinfit seems to be a bit easier!
Star Strider
Star Strider 2019년 1월 16일
@Janna Hinchliff — Please see my Comment to your Question.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by