Hi Francesco,
I understand that you want to train a NARX neural network and include a subset of recordings for validation. You can refer to the following code to create a validation set with 20% of the recordings:
net = narxnet(1:2,1:2,10);
net.divideMode = 'sample';
net.divideFcn = 'divideind'; % Use individual indices for division
net.divideParam.trainInd = 1:80;
net.divideParam.valInd = 80:100;
[Xs,Xi,Ai,Ts] = preparets(net,Xdata,{},Ydata);
[net,tr] = train(net,Xs,Ts,Xi,Ai)
Hope this helps!