If this is a one-time fix to display signals names, you can create a mask and edit the port labels in the mask "Icon" tab. For dynamic changes, follow the steps below:
To create the workaround to support your desired workflow, you need to place the “If” block inside of a masked subsystem and add a callback function to the input port. This callback will execute whenever a signal is connected to that port. Here are general steps to implement this function so that it will change the name of the ports in the masked subsystem based on the name of the input signal.
- Create a subsystem containing an “if” block
- Place a mask on the subsystem and promote the necessary parameters
- Write a callback function and link it to the input port of the subsystem
- Inside the function:
- Save the current block into a variable (“gcb”)
- Use “set_param” to set the “Name” parameter of the "Inport” found using “find_system”
- Use “find_system” to find the “Inport” inside the subsystem
- https://www.mathworks.com/help/simulink/slref/find_system.html
- Use “get_param” to get the line object from the “portHandle” input
- Use “get_param” to get the “Name” parameter from the line object
This allows the subsystem inport to inherit the name of the signal line entering it. Inside the same callback you can also change the name of the outport to also reflect the input signal name.
If you would like to reuse this block across your project, place it in a custom library. For the callback to work you will just need to ensure that the callback function is in the MATLAB path and that the ‘Allow library blocks to modify its contents’ check is enabled under the ‘Code’ tab in the Mask Editor.
This documentation link may also prove helpful: