Problem with network class variable on Matlab Function on Simulink

2 views (last 30 days)
Hello,
In my Simulink schematic I have a Matlab Function block, where I have written my code. In it, I use the function preparets, in an extrinsic way, defining it with coder.extrinsic('preparets').
net = load('NARX_CMON');
X = tonndata(up,true,false);
T = tonndata(yk',true,false);
[x,xi,ai] = preparets(net,X,{},T);
The problem arises when I load the neural network to a net variable, which I use in the preparets function. The error I get is the following:
"Found unsupported class for variable using function 'load'. MATLAB class 'network' found at 'net.net' is unsupported."
I understand that when converting the Matlab Function to C code for execution in Simulink, Simulink does not support Network class variables.
Since the C language does not support Network variables, how should I load the network to use it in the preparets function? what can I do to solve this problem? how can this be done?

Answers (1)

Abhishek Kumar Singh
Abhishek Kumar Singh on 23 Feb 2024
Edited: Abhishek Kumar Singh on 24 Feb 2024
Hi Haritz,
It looks like you're encountering limitations due to MATLAB Function blocks not supporting the direct use of certain MATLAB classes, such as network. Unfortunately, you cannot use the load function within a MATLAB Function block to load a neural network object.
For deep learning networks, MATLAB provides the coder.loadDeepLearningNetwork function, which is suitable for both simulation and deployment to standalone applications. However, please note that this function is intended for deep learning networks that are compatible with MATLAB Coder and may not support traditional neural networks from the Deep Learning Toolbox. For more information, you can refer to the following documentation resources:
  1. Load Pretrained Networks for Code Generation
  2. coder.loadDeepLearningNetwork
An alternative approach for traditional neural networks is to generate a Simulink block using the gensim function, which can then be integrated into your main Simulink model. This method is particularly useful if you're working with networks created with the Deep Learning Toolbox. More details can be found on the following documentation page:
  1. Creating Simulink models from a neural network
  2. network.gensim
If your network is a traditional feedforward or recurrent neural network from the Deep Learning Toolbox, you might need to pass the network object as an input parameter to the MATLAB Function block from the workspace, avoiding the use of the load function inside the block.
I hope this helps!

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!