MATLAB: Do the zero-valued elements of the state-space matrices for the Discrete State-Space block not appear in the code that Real-Time Workshop 6.6 (R2007a) generates

simulink coder

My model contains a Discrete State-Space block for which some of the parameters, e.g., A, B, C, and D, are matrices containing zeros. When I build the model using Real-Time Workshop, the zeros are missing from the generated code. For example, I set the A parameter equal to [1 2; 0 4] in Simulink; however, the model_data.c file that Real-Time Workshop generates shows the parameter as { 1.0, 2.0, 4.0 }.
Because I might update this value directly in the C-file at a later time, I need to force Real-Time Workshop to preserve such zeros.

Best Answer

In order to prevent Real-Time Workshop from eliminating parameter values equal to zero for the Discrete State-Space block, you must first declare those parameters to be tunable. You can do this from the "Optimization" tab of the "Configuration Parameters" dialog box:
1. Select the check box labeled "Inline parameters."
2. Click the adjacent button labeled "Configure."
3. Select all appropriate parameters in the left pane, and then click the "Add to table" button to add them "Global (tunable) parameters" list in the right pane.
4. Rebuild your code. Note that all zero entries should be preserved in your model_data.c file.