MATLAB: Don’t S-Function blocks with dynamic input and output ports update when saving the blocks in a library or model in Simulink 7.8 (R2011b)

blocklibrarymasknumberportssimulinkupdate

My Simulink model contains a Level 2 MATLAB S-Function block. The number of input and output ports are dynamically updated based on mask parameters.
The issue I am running into occurs when saving and loading the Simulink block in a library or model causes it appear invalid.
Even though the commands
get_param(gcb, 'NumInputPorts')
get_param(gcb, 'NumOutputPorts')
output the value I've inputted in my dialog mask parameter, the block that is drawn only contains 1 input and 1 output (the defaults).
If I manually set the number of input and output ports from the MATLAB Command Window as follows
set_param(gcb, 'NumInputPorts'
the block gets updated correctly. Why does this happen?

Best Answer

In order for the number of ports to update properly, the "Allow Library Block to Modify its Content" option must be enabled for the block. To do this, please take the following steps:
1. Right click the block and select 'Edit Mask'.
2. Go to the 'Initialization' tab in the Mask Editor.
3. Check the "Allow Library Block to Modify its Content" checkbox.
OR
1. Select the block
2. Enter this command at the MATLAB Command Window:
>> set_param(gcb, 'MaskSelfModifiable', 'on');