Hi fritz,
The issue stems from how MATLAB Compiler SDK handles neural network objects. When you compile your MATLAB code into a Python package, the neural network objects are converted to plain structures. As a result, when you try to call them like functions, MATLAB can not find the expected function behaviour, leading to the "Index exceeds the number of array elements" error.
A workaround is to avoid using the network objects directly after compilation. Instead, you can "freeze" your neural network as a standalone MATLAB function using the ‘genFunction’ command. This converts your trained network into a regular function that can be called safely in your compiled environment.
Consider this example, suppose you have a trained network saved as net. You would generate a standalone function with:
genFunction(net, 'netFunction');
Then, modify your evaluation function to use this generated function:
function e = network_evaluation(s0, s1, s2, s3, s4, s5)
% Prepare the input vector
in = [s0; s1; s2; s3; s4; s5];
% Call the standalone network function
e = netFunction(in);
end
With this approach, when you compile your code and call it from Python, you won't encounter the object conversion issue, and the network evaluation should work without errors.
For a better understanding of the above solution, refer to the following MATLAB documentation:
