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

errormatlabfnc not supportedneural networkreal time workshopsimulink

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.

Best Answer

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.
Related Question