How to get names of input ports on simulink block?

11 views (last 30 days)
Is there a way to get the name of the input ports on a Simulink block? I don't mean the names of the signals coming into the block (which are fairly simple to get), but the names assigned to the inports themselves?

Answers (1)

Rajanya
Rajanya on 11 Feb 2025
You can utilize the 'get_param' function on any custom Simulink block that contains Inports or Outports to obtain the handle for that block. With this handle, you can then use 'find_system' to identify all 'Inports' or 'Outports' and subsequently retrieve their names.
blockHandle=get_param(gcb,'Handle'); %set the current block appropriately
portHandle=find_system(blockHandle,'BlockType','Inport');
portNames = cellstr(get_param(portHandle, 'Name'));
For more information on 'get_param' and 'find_system', you can refer to their respective documentation pages by executing the following commands from MATLAB Command Window:
doc get_param
doc find_system
Thanks.

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!