Generic function to make a prediction for a time series if a. Matlab code ready to run. Simple and robust implementation under 40 lines.