That looks like my code from a very long time ago!
If the Statistics and Machine Learning Toolbox is available, use fitlm and predict for this (the regress function is also an option, so consider it as well) —
x = 0:0.1:9; % Create Data
y = 1.5*x+0.5 + randn(size(x))*0.5; % Create Data
mdl = fitlm(x(:),y(:))
Cefs = mdl.Coefficients.Estimate % Recover Coefficient Values (If Desired)
[ypred,yci] = predict(mdl,x(:), 'Prediction','observation');
figure
plot(x, y, '.g')
hold on
plot(x, ypred, '-r')
plot(x, yci, '--r')
hold off
grid
legend('Data','Linear Fit','95% Confidence Intervals', 'Location','best')
Remember to use the 'Prediction','observation' name-value pair to get the correct confidence intervals.
.


