MATLAB: How to force the intercept of a regression line to zero

linear regressionzero intercept

Hi; How to set the intercept of a regression line,, resulted from fitlm, to zero?
clc
X = 1:10
y = [1, 2, 2.9, 4, 5.1, 6, 7, 7.8, 8.6, 9.5]
dlm = fitlm(X,y)
Thank you, in advance, for your help.

Best Answer

There are 2 main ways you can do this:
dlm = fitlm(X,y,'Intercept',false);
or using Wilkinson notation:
dlm = fitlm(X,y,'y~x1-1');
I would highly suggest learning the Wilkinson notation, as this allows you to fit models and specify the form of the equation you would like to fit.