How can I build an trendline through a fixed point?
22 次查看(过去 30 天)
显示 更早的评论
I have scatter data and need to fit it with a curve (line) which passes through one exact and fixed point (0,0).
How can I do this?
Thank's for respond.
Iaroslav.
0 个评论
回答(3 个)
Star Strider
2015-4-15
If you do not include a constant (intercept) term in your model, it will force an intercept at (0,0). So if it is a straight line, to fit (x,y) data, this works:
x = randi(10, 10, 1); % Create Data
y = randi(50, 10, 1); % Create DAta
B = x(:)\y(:); % Regression Of Line Through Origin
yfit = x(:)*B; % Calculate Fitted Line
figure(1)
plot(x, y, 'bp') % Plot Data
hold on
plot(x, yfit, '-r') % Plot Fitted Regression Line
hold off
grid
axis([0 max(x) 0 max(y)])
2 个评论
Iaroslav Gritsayenko
2015-4-15
2 个评论
Star Strider
2015-4-15
MATLAB functions all want (or will insert) a non-zero intercept term in the regressions they calculate. If you want a general case that will always fit a zero intercept, the code in my Answer will provide it.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!