Using neural network in function block from Simulink
8 次查看(过去 30 天)
显示 更早的评论
My Simulink workspace looks like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162620/image.png)
and the function contains just a few lines:
function y = mysimulinkfunction(u,v)
%#codegen
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
net([1;0])
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.
0 个评论
回答(5 个)
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:
genFunction(___,'MatrixOnly','yes')
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
2018-1-9
编辑:Simon Christmann
2018-1-9
Here is the full solution for Zeljko Tomicevic and anyone who found this thread on Google
0 个评论
XIN HE
2019-6-5
Did you got it fixed? I got the similar proble, could you share your solution ?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning with GPU Coder 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!