I think I have cracked it if anyone is interested.
Fairly simple if you use nlinfit. (I would be interested to know if you can get the same results from lsqcurvefit though if anyone has the answer).
So what you so is
function F = myfun(p,X)
F = (p(1)*X)+p(2); end
!sepearte file!
X = [1:4]; Y = [5:8]; % or something like this
[beta,resid,J,COVB,mse] = nlinfit(X,Y,@myfun2,[1;1]) ; [ci se] = nlparci(beta,resid,'covar',COVB);
%beta(1) is coefficient p(1)(the gradient) and beta(2) is the intercept. % se(1) is the error on the gradient and se(2) is the error of the intercept.
Easy, i feel a little ashamed..
oh yeah, you also had to alter nlparci
by going
open nlparci in matlab
then changing on the first line
function ci = nlparci(beta,resid,varargin)
to
function [ci se] = nlparci(beta,resid,varargin)
and thats it...
Thanks
Best Answer