Clear Filters
Clear Filters

How to call neural network .mat file during the Simulink simulation?

2 views (last 30 days)
Hi,
I have made an neural network model by using 'fitnet' function in Matlab and saved it as 'ANN2.mat'
In my simulink model, I would like to use this nn model to predict an output. (the simulink model is expressed below)
What I have done is put a 'm-function' and script is like this:
function y = fcn(Tset, Tsa, Tra, Qair, dT_w)
load ANN2
input = [Tset, Tsa, Tra, Qair, dT_w]'
output = net(input)
y = output;
But an error occurs:
As I don't know much about matlab & simulink, it is hard for me to understand the error and how to solve.
What is wrong with my script?
Is there any method to import my neural network model as .m or .mat file and execute it?
Because I'm trying to train nn model with new data which is generated by every simulink timestep, I want to avoid using blocks supporting from simulink.
Thank you very much in advance for your time.

Answers (1)

Harsha Priya Daggubati
Harsha Priya Daggubati on 27 Jul 2020
Hi,
I guess the error might be because of using 'net'. Since you saved the network as ANN2 you need to use ANN2(input) instead of net.
You can also look at the following link for a list of options available to use Simulink to train a neural network:
Hope this helps!

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!