Extend linear regression line to an offset

18 visualizaciones (últimos 30 días)
caroline Øhrstrøm
caroline Øhrstrøm el 27 de Mzo. de 2020
Respondida: Star Strider el 27 de Mzo. de 2020
Hello
I am working an a calibration and I would like my graph to go to the offset, meaning it has to continue from their it though 0.0, but do not know how to set the range, my code is as following.
X = [0.6,1.6,2.6,3.6,4.6,5.6,];
Y = [23500, 87780, 153651, 220054, 283688,344890];
myFit = LinearModel.fit(X,Y);
plot(myFit)
Hope someone can help:)

Respuestas (1)

Star Strider
Star Strider el 27 de Mzo. de 2020
I am not certain what you are asking.
Two possibilities:
X = [0.6,1.6,2.6,3.6,4.6,5.6,];
Y = [23500, 87780, 153651, 220054, 283688,344890];
B0 = X(:) \ Y(:); % Force Zero Intercept
B0Fit = [0 max(X)] * B0;
Bnz = [X(:) ones(size(X(:)))] \ Y(:); % Non-Zero Intercept
BnzFit = [0 1; max(X) 1] * Bnz;
figure
plot(X,Y,'p')
hold on
plot([0 max(X)], B0Fit,'-r')
plot([0 max(X)], BnzFit,'-g')
hold off
grid
legend('Data', 'Force Zero Intercept', 'Extend To Zero', 'Location','E')
This extends both regressions through ‘X=0’. One forces a (0,0) intercept (returning only the slope), the other does not (returning both the slope and the non-zero intercept).

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by