- 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
- Save the current block into a variable (“gcb”)
Dynamically change block mask to display input signal names
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 3 Nov 2022
Réponse apportée : MathWorks Support Team
le 3 Nov 2022
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)".
Réponse acceptée
MathWorks Support Team
le 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:
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Subsystems dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!