Using neural network in function block from Simulink

16 ビュー (過去 30 日間)
Simon 2014 年 5 月 13 日
コメント済み: michael bronnmann 2020 年 10 月 19 日
My Simulink workspace looks like this:
and the function contains just a few lines:
function y = mysimulinkfunction(u,v)
global net;
y = net([u;v]);
The object "net" is an already trained feed forward network residing in my workspace which can be successfully called from the command line via
and writes the correct answer (which is 1.0).
However Simulink throws several errors when I try to run it, first:
Global declaration not resolved to a Data Store Memory block registered via the Ports and Data Manager.
and 2nd:
Could not find initial value for global variable 'net'.
Those errors sound like it is not possible to call neural networks that way, however I just want to know if there's another possibility than gensim(net) to use a NN in Simulink.

回答 (5 件)

Ryan Livingston
Ryan Livingston 2014 年 5 月 15 日
In the MATLAB Function Block global variables are linked to Data Store Memory blocks rather than the MATLAB workspace:
However, I don't believe that Neural Network objects are directly supported for code generation.
The simplest alternative to gensim I've seen to utilize a trained NN in the MATLAB Function Block or MATLAB Coder is genFunction:
That page describes how to create a MATLAB Function Block/MATLAB Coder compliant MATLAB function via the syntax:
This will produce a MATLAB function which you should simply be able to call from inside your MATLAB Function Block to simulate the NN.

Simon Christmann
Simon Christmann 2018 年 1 月 9 日
編集済み: Simon Christmann 2018 年 1 月 9 日

Here is the full solution for Zeljko Tomicevic and anyone who found this thread on Google

XIN HE 2019 年 6 月 5 日
Did you got it fixed? I got the similar proble, could you share your solution ?

michael bronnmann
michael bronnmann 2019 年 8 月 27 日
Hey, is there any way to use "SeriesNetwork" in Simulink?
  2 件のコメント
yassine kebbati
yassine kebbati 2020 年 10 月 18 日
were you able to find a way to do that?
michael bronnmann
michael bronnmann 2020 年 10 月 19 日
Not yet. It seems up to now, there is no (simple) way...


Asma A Bder Muhmed
Asma A Bder Muhmed 2020 年 5 月 19 日
How I can put these numeres in equation?


Help Center および File ExchangeDeep Learning with GPU Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by