HI Francisco,
To perform multi-step (e.g., three-step) ahead prediction with a NARX network in MATLAB, you first convert your trained network to closed-loop mode using closeloop. Then, you prepare the initial input and state sequences using the last known values from your training data. For each future step, you provide the necessary input (if any) and let the network recursively predict the next value, using its own previous output as input for the next step. This process does not require future target values, as the network is now operating in prediction mode. The code provided demonstrates how to implement this process for three steps ahead.
% Assume you have already trained your NARX network as you described.
% Step 1: Convert to closed-loop for multi-step prediction
netc = closeloop(net);
% Step 2: Prepare initial input states
% Use the last available data points from your input series
% Let's say you want to start predicting after your last known target
% Prepare the initial input for prediction (last inputs used during training)
lastInputs = y(end-netc.numInputDelays+1:end); % last inputs to the net
lastStates = y(end-netc.numLayerDelays+1:end); % last outputs to the net
% Step 3: Predict next 3 steps
numSteps = 3;
futureInputs = cell(1, numSteps); % If you have future known inputs, fill here. Otherwise, zeros.
for i = 1:numSteps
futureInputs{i} = 0; % or whatever your exogenous input is, if any
end
% Simulate the network for 3 steps ahead
[yPred,~,~] = netc(futureInputs, lastInputs, lastStates);
% yPred will be a cell array with the 3 predicted outputs
disp('3-step ahead predictions:');
cell2mat(yPred)