For details, please refer to: http://lab.fs.uni-lj.si/lasin/wp/IMIT_files/neural/nn05_narnet/
Format compact% Data SETTINGSN = 249; % Number of Samplesnu = 224; % Number of learning Samplesy = data;% Input your data% prepare training Datayt = Con2seq (Y (1:nu) ');% prepare Test datayv = Con2seq (Y (nu+1:end) ');% Choose a Training function% for a list of all Training functions type:help nntrain% ' TRAINLM ' I s usually fastest.% ' TRAINBR ' takes longer but may is better for challenging problems.% ' TRAINSCG ' uses less memory. Ntstool falls back to this in the low memory SITUATIONS.TRAINFCN = ' TRAINLM '; % levenberg-marquardt% Create a nonlinear autoregressive networkfeedbackdelays = 1:5;hiddenlayersize = 40;net = narnet (fee Dbackdelays,hiddenlayersize, ' open ', TRAINFCN); [Xs,xi,ai,ts] = Preparets (NET,{},{},YT);% train NET with prepared training Datanet = train (net,xs,ts,xi,ai);% View trained net% Close feedback for recursive predictionnet = Closeloop (net);% view Closeloop version of a NetView (net);%%%recursive Prediction on test data% prepare test data for network Simulationyini = YT (End-max (feedbackdelays) +1:end); % initial values from training data% combine initial values and test data ' YV ' [xs,xi,ai] = Preparets (Net,{},{},[yini yv]);
Prediction of time series with NAR neural network in MATLAB timeseries prediction