Yes, you can save the gradient and performance values for each epoch during the training process in MATLAB using a custom script. To do this, you'll need to modify the training loop and add code to save the desired information to arrays or data structures. Here's a high-level example of how you can achieve this:
gradients = zeros(num_epochs, 1);
performance = zeros(num_epochs, 1);
[net, gradient, current_performance] = train_one_epoch(net, data);
gradients(epoch) = gradient;
performance(epoch) = current_performance;
fprintf('Epoch %d - Gradient: %.4f - Performance: %.4f\n', epoch, gradient, current_performance);
In this example, you'll need to replace train_one_epoch with your actual training function that performs one epoch of training, computes the gradient, and evaluates the performance. Make sure your training function returns the current gradient and performance values.
You can customize the code above to suit your specific neural network architecture and training setup. Additionally, you can choose to save the gradient and performance values to a file if you want to analyze the results after the training is complete.