How can I create a dynamic output port name that updates based on an action and change output text color using system object?

6 views (last 30 days)
Looking at the image below, how can I turn the output port name to red instead of the default black color using system object? How can I update the port name to what the user has selected? For example, instead of 'NC', if the user select 3, I want to change the output port name to I3 with the color black. Thanks.
  2 Comments
Raghava S N
Raghava S N on 7 Apr 2025
You can make use of a mask for the subsystem through which you can set the colour and value of the output port label.
For more information about subsystem masks and the mask editor, you may refer this link - https://www.mathworks.com/help/simulink/gui/mask-editor-overview.html
Hope that solves your query!
Wilfried
Wilfried on 7 Apr 2025
Edited: Wilfried on 17 Apr 2025
Thank you Raghava for your response. I know about the mask editor, but I am trying to code it in the system object file without having to go to the mask editor if possible so I can have all the code in one file.

Sign in to comment.

Answers (1)

colordepth
colordepth on 17 Apr 2025
Edited: colordepth on 17 Apr 2025
As of MATLAB R2024b, there doesn't appear to be a built-in method to accomplish this using system objects. Moreover, attempting to modify the block mask programmatically results in an error, as illustrated below:
The only way to change the icon (including port labels and colors) for blocks using system objects is by using the mask editor. The steps suggested by @Raghava S N work well to achieve such customization.
Additional information: When you save a system object mask from the mask editor, it is serialized as an XML file in the same directory as your system object M-file. This means that both the system object and its mask customization code are accessible in one folder location, as shown below. However, any changes must be made through the mask editor.

Community Treasure Hunt

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

Start Hunting!