How do I get the error of a fitting function?

25 次查看(过去 30 天)
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 个评论
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