If you have the variables in a table or dataset array,
then `0` must represent the response variable depending
on the position of the response variable. The following example illustrates
this.

Load the sample data and define the dataset array.

load hospital
ds = dataset(hospital.Sex,hospital.BloodPressure(:,1),hospital.Age,...
hospital.Smoker,'VarNames',{'Sex','BloodPressure','Age','Smoker'});

Represent the linear model `'BloodPressure ~ 1 + Sex
+ Age + Smoker'` in a terms matrix. The response variable
is in the second column of the dataset array, so there must be a column
of 0s for the response variable in the second column of the terms
matrix.

T = [0 0 0 0;1 0 0 0;0 0 1 0;0 0 0 1]

T =
0 0 0 0
1 0 0 0
0 0 1 0
0 0 0 1

Redefine the dataset array.

ds = dataset(hospital.BloodPressure(:,1),hospital.Sex,hospital.Age,...
hospital.Smoker,'VarNames',{'BloodPressure','Sex','Age','Smoker'});

Now, the response variable is the first term in the dataset
array. Specify the same linear model, `'BloodPressure ~ 1
+ Sex + Age + Smoker'`, using a terms matrix.

T = [0 0 0 0;0 1 0 0;0 0 1 0;0 0 0 1]

T =
0 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

If you have the predictor and response variables in
a matrix and column vector, then you must include `0` for
the response variable at the end of each term. The following example
illustrates this.

Load the sample data and define the matrix of predictors.

load carsmall
X = [Acceleration,Weight];

Specify the model `'MPG ~ Acceleration + Weight + Acceleration:Weight
+ Weight^2'` using a term matrix and fit the model to the
data. This model includes the main effect and two-way interaction
terms for the variables, `Acceleration` and `Weight`,
and a second-order term for the variable, `Weight`.

T = [0 0 0;1 0 0;0 1 0;1 1 0;0 2 0]

T =
0 0 0
1 0 0
0 1 0
1 1 0
0 2 0

Fit a linear model.

mdl = fitlm(X,MPG,T)

mdl =
Linear regression model:
y ~ 1 + x1*x2 + x2^2
Estimated Coefficients:
Estimate SE tStat pValue
(Intercept) 48.906 12.589 3.8847 0.00019665
x1 0.54418 0.57125 0.95261 0.34337
x2 -0.012781 0.0060312 -2.1192 0.036857
x1:x2 -0.00010892 0.00017925 -0.6076 0.545
x2^2 9.7518e-07 7.5389e-07 1.2935 0.19917
Number of observations: 94, Error degrees of freedom: 89
Root Mean Squared Error: 4.1
R-squared: 0.751, Adjusted R-Squared 0.739
F-statistic vs. constant model: 67, p-value = 4.99e-26

Only the intercept and `x2` term, which correspond
to the `Weight` variable, are significant at the
5% significance level.

Now, perform a stepwise regression with a constant model as
the starting model and a linear model with interactions as the upper
model.

T = [0 0 0;1 0 0;0 1 0;1 1 0];
mdl = stepwiselm(X,MPG,[0 0 0],'upper',T)

1. Adding x2, FStat = 259.3087, pValue = 1.643351e-28
mdl =
Linear regression model:
y ~ 1 + x2
Estimated Coefficients:
Estimate SE tStat pValue
(Intercept) 49.238 1.6411 30.002 2.7015e-49
x2 -0.0086119 0.0005348 -16.103 1.6434e-28
Number of observations: 94, Error degrees of freedom: 92
Root Mean Squared Error: 4.13
R-squared: 0.738, Adjusted R-Squared 0.735
F-statistic vs. constant model: 259, p-value = 1.64e-28

The results of the stepwise regression are consistent with the
results of `fitlm` in the previous step.