Clear Filters
Clear Filters

Dynamically change block mask to display input signal names

36 views (last 30 days)
I'm using an if/else subsystem block, and I would rather see meaningful names on the conditions instead of just a port number. For example, if my first input port is from signal My_Timer, and my condition is u1<10, I'd rather see the port labeled as "My_Timer" and the condition as "if(My_Timer < 10)" instead of port labeled as "u1" and condition as "if(u1 < 10)".

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 3 Nov 2022
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.
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:

More Answers (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!