MATLAB: Simulink.Bus and Embedded Coder

Embedded Coderstructures

I have a few Matlab files that work correctly and implement the functionality I need. I am now trying to port them to Simulink/Embedded Coder using the "Matlab Function" block. After resolving a number of "not supported" type problems, I am stuck on a problem that I don't know how to resolve.
The issue is this- the Matlab functions use a structure to keep track of the system state. They modify the state and pass it on to each other. Embedded Coder indicated that structs were not supported, so I added the following line that I found in a Matlab blog post- "outputState = Simulink.Bus.createObject(state);"
That seemed to improve things in that Embedded Coder got "farther". Now, though, it says the following- "Function 'Simulink.Bus' is not supported for code generation. Consider adding coder.extrinsic('Simulink.Bus') at the top of the function to bypass code generation." I tried adding the extrinsic, but it just came up with another error.
Can you use structs in Embedded Coder? If so, what do I need to do. I could break the state struct into individual values/arrays, but it would be very ugly and painful. Thanks for your time and help.

Best Answer

You need to specify the Bus type on the Ports and Data Manager of the MATLAB Function block, not in the MATLAB code itself. Please see Attach Bus Signals to MATLAB Function Blocks.
Related Question