Can I view the port number and port name of a subsystem or model reference from the top level?

18 views (last 30 days)
Inport and outport blocks in subsystems and model references have both a name and a number which are used to identify them. However, only the port name is displayed on the block that includes them in the parent system.
For example, a subsystem with the following inport blocks has the port labels shown below:
          
How can I view both the names and the port numbers from the parent system?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 31 Mar 2021
This feature is currently not a built-in feature. However, this behavior can be created by masking the block in question and using icon drawing commands to automatically label the ports with their names and numbers.
One example of what this code might look like for inports is as follows:
% comment out or remove the line for the type of system not being used
sys = gcb; % for subsystems
sys = get_param(gcb, 'ModelName'); % for model references
% find all block in the system of the given type. Ex. "Inport", "Outport"
inports = Simulink.findBlocksOfType(sys, 'Inport');
% loop through all blocks found
for idx = 1:length(inports)
    num = get_param(inports(idx), 'Port'); % get the port number
    name = get_param(inports(idx), 'PortName'); % get the port name
    port_label('input', idx, [num '. ' name]); % set the port label. See the port_label documentation for details
end
Using code like this can turn the subsystem port labels from the one shown above to the one below:
For more details on the port_label command, see https://www.mathworks.com/help/simulink/slref/port_label.html
For more details on mask icon drawing commands in general, see https://www.mathworks.com/help/simulink/ug/create-mask-icon.html

More Answers (0)

Categories

Find more on Author Block Masks in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!