Your model is the linear regression of the first 2000 points. To get the model predictions for the rest of the data, ‘plug in’ the values for your independent variable for the rest of your data in your model. The output of your model are the predictions for those values. To get the error, subtract your predictions from the dependent variable data for those same values of the independent variable.
To illustrate:
x = linspace(0,200);
y1 = 0.5*x(1:50) + 0.1*randn(1,50) + 1.2;
y2 = 0.6*x(51:100) + 0.1*randn(1,50) + 1.5;
b = polyfit(x(1:50), y1, 1);
yfit = polyval(b, x);
model_error = yfit - [y1 y2];
figure(1)
plot(x, [y1 y2], 'xr')
hold on
plot(x, yfit, '-b')
hold off
grid
legend('Data', 'Model Fit', 'Location','SE')
Best Answer