Borrar filtros
Borrar filtros

How can I build an trendline through a fixed point?

16 visualizaciones (últimos 30 días)
Iaroslav Gritsayenko
Iaroslav Gritsayenko el 15 de Abr. de 2015
Comentada: pfb el 15 de Abr. de 2015
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.

Respuestas (3)

Star Strider
Star Strider el 15 de Abr. de 2015
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 comentarios
pfb
pfb el 15 de Abr. de 2015
Editada: pfb el 15 de Abr. de 2015
this is definitely more professional :)
Star Strider
Star Strider el 15 de Abr. de 2015
Thank you.

Iniciar sesión para comentar.


pfb
pfb el 15 de Abr. de 2015
Editada: pfb el 15 de Abr. de 2015
Is that a straight line or a curve? And, in the second case, which curve?
In the first case you're basically expecting that y is proportional to x. So y./x should be roughly constant, and mean(y./x) would be an estimate of the slope, right?

Iaroslav Gritsayenko
Iaroslav Gritsayenko el 15 de Abr. de 2015
Thank you very much, I understood how to do it.
My line will have equation y= a*x+b, where b=0; And a=mean(Y./X)
And does mathlab have some function to build fitting curve (not only line) with the fixed point in general case?
  2 comentarios
Star Strider
Star Strider el 15 de Abr. de 2015
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.
pfb
pfb el 15 de Abr. de 2015
perhaps custom equation in cftool?

Iniciar sesión para comentar.

Categorías

Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by