MATLAB: Unexpected code generated when subsystem is changed to atomic

coderpointssignalsignalssimulinksimulink codertestvirtual

In my model, I set two signals as test points. When I proceed to generate code, the code is as expected. When I change one of the subsystems in the model to 'Atomic', I seem to observe some extraneous code generated (see below). Why does this happen?

Best Answer

The C-API generates code for all signals, not just test points. The reason you are seeing new signals appear is because when the subsystem is made atomic, some signals that were previously virtual become non-virtual and thus show up in the C-API. For more information on Virtual signals, please review the following documentation page: https://www.mathworks.com/help/simulink/ug/virtual-signals.html
However, these signals will not appear when generating code using Embedded Coder as it employs optimizations not available in Simulink Coder to make the generated code more efficient. Consider using Embedded Coder if the aim is to eliminate these extraneous signals.