How to train neural network in Simulink?
3 views (last 30 days)
Show older comments
Hello
I have made a neural network block in simulink,now I want to train it again, which code makes it possible to train exact this neural network block???
If I want to give input to this block and then get the output, how can I connect input for example like a matrix to NN block??
Thanks
1 Comment
Answers (1)
Purvaja
on 28 Aug 2025
In Simulink, models that include neural networks or other machine learning components typically perform inference or prediction during simulation. When you run a model containing a neural network block, it uses the pre-trained weights to generate outputs based on the input data provided.
However, standard Simulink blocks do not update weights or learn from new data during runtime. The learning or training process must be conducted separately using MATLAB code, where you can use functions like trainNetwork to adjust the weights based on training data. Once the network is trained, you can save the model and load it into Simulink for prediction.
If you want a model to learn continuously while running, you would need to implement a custom training loop within your Simulink model, which is more complex and typically involves using MATLAB Function blocks or Stateflow to manage the training process dynamically. This approach allows for online learning, but it requires careful design to ensure stability and performance.
Now to re-use the neural network block, you can follow the same steps as you had used before, change the inputs, retrain it in MATLAB to update weights and then load it in simulink in "Predict" block, or whichever way you did it before.
Incase you want to reset states while training like for LSTMs, you can refer to below resources:
- Predict and Update Network State in Simulink: https://www.mathworks.com/help/deeplearning/ug/predict-update-network-simulink.html
- Classify and Update Network State in Simulink : https://www.mathworks.com/help/deeplearning/ug/classify-update-network-simulink.html
Hope this solves your doubt!
If you want more clear picture, feel free to provide more details related to your neural network setup.
0 Comments
See Also
Categories
Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!