MATLAB: Error in the intercept

error

I think this might be a dumb question, but how do you find the error of the intercept for a straigh line graph that I have fittded using polyfit? and polyval. I got the error for the slope by doing something like this.
[p2,s2] = polyfit(A2,B2,1);
[f2,delta] = polyval(p2,x,s2);
deltaf2=s2.normr/sqrt(s2.df);
C2=deltaf2^2*inv(s2.R)*inv(s2.R)';
deltap2=sqrt(diag(C2));
ok

Best Answer

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