フィルターのクリア

Trouble using polyfit that separated straight fit from original data points

2 ビュー (過去 30 日間)
James
James 2013 年 11 月 4 日
コメント済み: James 2013 年 11 月 6 日
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

採用された回答

dpb
dpb 2013 年 11 月 4 日
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.

その他の回答 (1 件)

Image Analyst
Image Analyst 2013 年 11 月 4 日
When you use polyval() to get your estimated x values, you need to pass in S and mu to get values in your original range. See this demo:
x = -10:10;
y = x + 10 + 20*rand(1, length(x));
plot(x,y,'bd-', 'LineWidth', 3, 'MarkerSize', 15);
ylim([0 40]);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
grid on;
% Fit a line to the noisy data
[coefficients, S, mu] = polyfit(x, y, 1);
% Get the fit. YOU NEED TO PASS IN S AND MU!
yFitted = polyval(coefficients, x, S, mu);
% Plot it
hold on;
plot(x,yFitted,'r*-', 'LineWidth', 3, 'MarkerSize', 15);

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by