MATLAB: How to add or remove specific S-function block ports in Simulink 6.5 (R2006b)

deleteorderingportportssimulink

I use an S-function parameter to control the number of input and output ports displayed by my S-function block. If I specify a value for the parameter that reduces the number of S-function block output ports, Simulink always removes ports from the end of the block. However, the S-function block ports that Simulink removes were once connected to other blocks. This situation forces me to rewire much of my model. Instead, I want to be able to remove specific S-function block ports while keeping all other ports intact.

Best Answer

The ability to add or remove specific S-function block ports is not available in Simulink 6.5 (R2006b).
To work around this issue, you can put your S-function block inside a masked Subsystem block. This creates another hierarchical layer for your S-function block, such that it connects to the rest of the model through the Subsystem block's inports and outports. Within the context of that Subsystem, you can use a mask callback function to implement logic that allows the block to maintain its wiring. For example, use the:
1. ADD_LINE and DELETE_LINE functions to create and remove signal lines
2. SET_PARAM function to change the port number of a specific port