How to understand the input and output arguments of preparets function for network training

For training NARX network, we need to prepare input and target time series data using preparets function. However, the preparets function has many input and output arguments which are confused for me to understand their functioning. I have read the examples about preparets, yet it is still difficult to understand. What is the best practice to understand the preparets and correctly use it under different network training scenarios ?
help preparets
preparets - Prepare input and target time series data for network simulation or training This MATLAB function takes these arguments: net — Neural network Xnf — Non-feedback inputs Tnf — Non-feedback targets Tf — Feedback targets EW — Error weights (optional)and returns these arguments: Xs — Shifted inputs Xi — Initial input delay states Ai — Initial layer delay states Ts — Shifted targets EWs — Shifted error weights shift — The number of timesteps truncated from the front of X and T in order to properly fill Xi and Ai. Syntax [Xs,Xi,Ai,Ts,EWs,shift] = preparets(net,Xnf,Tnf,Tf,EW) Input Arguments net - Input network network Xnf - Non-feedback inputs cell array Tnf - Non-feedback targets cell array Tf - Feedback targets cell array EW - Error weights cell array Output Arguments Xs - Shifted inputs cell array Xi - Initial input delay states cell array Ai - Initial layer delay states cell array Ts - Shifted targets cell array EWs - Shifted error weights cell array shift - Timesteps scalar Examples openExample('nnet/PrepareDataForOpenAndClosedLoopNetworksExample') See also adddelay, closeloop, narnet, narxnet, openloop, removedelay, timedelaynet Introduced in Deep Learning Toolbox in R2010b Documentation for preparets doc preparets
EDIT: removed copyright code.

 Accepted Answer

Hi,
'preparets' is used to prepare and align time series data for dynamic neural networks such as NARX, NAR, and time-delay networks prior to training or simulation. Below is a detailed explanation:
  • The function automatically applies the input and layer delays defined in the network ('net.inputDelays', 'net.layerDelays') to ensure the data is consistent with the network architecture.
  • It partitions the data into:
  • Initial delay conditions → 'Xi' (input states) and 'Ai' (layer states)
  • Aligned training/simulation data → 'Xs' (inputs) and 'Ts' (targets)
  • The function removes the initial timesteps required to fill delay buffers. The number of removed samples is returned as 'shift'.
Input arguments interpretation:
  • 'net' → neural network object
  • 'Xnf' → external (non-feedback) inputs
  • 'Tnf' → non-feedback targets
  • 'Tf' → feedback targets (used in NARX configurations)
  • 'EW' → optional error weights
Output arguments interpretation:
  • 'Xs' → shifted and aligned inputs
  • 'Xi' → initial input delay states
  • 'Ai' → initial layer delay states
  • 'Ts' → shifted and aligned targets
  • 'EWs' → shifted error weights
  • 'shift' → number of truncated initial timesteps
  • For a typical open-loop NARX network (training phase):['Xs', 'Xi', 'Ai', 'Ts'] = 'preparets'('net', 'X', {}, 'T')
  • For a closed-loop configuration (simulation/prediction phase):['Xs', 'Xi', 'Ai', 'Ts'] = 'preparets'('net', 'X', 'T', 'T')
  • Users should not manually shift or align time series data, as 'preparets' is designed to handle all delay and alignment operations internally.
  • All time series data must be provided as cell arrays, where each cell represents one timestep.
  • The function is typically called just before 'train' or 'sim', ensuring compatibility between the data and the network.
Please refer to the following documentation for more details:
I hope this help!

More Answers (0)

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Products

Release

R2025a

Asked:

on 21 Mar 2026

Answered:

on 27 Mar 2026

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!