MATLAB: Trouble using polyfit that separated straight fit from original data points

polyfit

Hi all,
I am plotting some data from a power-inverse law and using the following:
loglog(E2dist,E2PrdB,'+g'), hold on
p = polyfit(log(E2dist),log(E2PrdB),1);
m = p(1);
b = exp(p(2));
%mean=mu(1);
%std=mu(2);
loglog(E2dist, b.*E2dist.^m,'-m*');
This works fine. But when I change to
[p,S,mu] = polyfit(log(E2dist),log(E2PrdB),1);
my straight line fit is separated vertically from my original data points?
Hope you can help.
cheers

Best Answer

  • From
    doc polyfit
    [P,S,MU] = polyfit(X,Y,N) finds the coefficients of a polynomial in
    XHAT = (X-MU(1))/MU(2) where MU(1) = MEAN(X) and MU(2) = STD(X).
    It's a "feature" that's non-intuitive, indeed. Would seem to have been better to use a flag to ask for/control centering rather than just the form of the output.