Problem building C++ code from a neural network Simulink model

Hi, I have used nftool to create and train a neural network. I want to add its functionality in a C++ program so I needed to convert it somehow into C++ code. Nftool has the option of automatically exporting the simulink model of a trained neural network and I did so, in order to covert it to C++ code using Real-Time Workshop. Problem is that when I try to build it, I get the following "Model error":
".../Neural Network/Process Output 1/removeconstantrows_reverse/MATLAB Fcn", block type "MATLABFcn": Not yet supported by Real-Time Workshop"
When I click on the error, I am presented with a block diagram with a "Matlab Function" square highlighted. When I click the square, I see that a "flipud" function is used, which I suspect is the source of the problem.
Is there another way to extract the functionality of a neural network in C++ and if not, what should I do?
Thank you in advance.

 Respuesta aceptada

You can replace the MATLAB Fcn block with a corresponding Simulink library blocks-based implementation that imitates flipud. If the size of the input is fixed and is a small number, it might be as simple as using a Demux block to separate out the rows and then use a Mux block to concatenate them back in reverse order.
Another easier alternative is to replace the MATLAB Fcn block with an Embedded MATLAB Fcn block, which supports flipud for code-generation. Your Embedded MATLAB Fcn can simply be:
function y = flipud_fcn(u)
%#eml
y = flipud(u);
Essentially, you need to convert the flipud functionality to a form that is supported for code-generation.

1 comentario

Thank you very much for your prompt answer.
I'm afraid I have no experience with simulink at all in order to manually replace the functionality of the specific function block, I just wanted to use it as a passing stage so as to embed the neural network's functionality in a C++ program.
As I can see, the block that causes the problem is a part of a "removeconstantrows_reverse" block. Are there any references I could study in order to get acquainted with the way I could use an Embedded MATLAB function?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink Coder en Centro de ayuda y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by