MATLAB: Fit a constant only linear regression model using ‘fitlm’

fitting

I have the following simple regression model
y(t) = B + u(t)
where B=1 and u(t) are random drawings from the standard normal distribution. Also n = 100. I would like to fit a constant only linear regression model but am unsure how to do so. I imagine I have to use 'fitlm', but for some reason cannot specify that there are no predictor variables . My code so far is simply:
b = 1
u = randn(100,1)
y = b + u

Best Answer

If you wanted to fit this using fitlm you could do the following:
fit1 = fitlm(ones(size(y)),y,'y~1');