How to obtain the source and destination block names and port numbers connected by a signal in Simulink?
12 views (last 30 days)
Show older comments
MathWorks Support Team
on 23 Jan 2019
Answered: MathWorks Support Team
on 27 Mar 2019
If I click on a certain signal in a Simulink model, how can I programmatically obtain the names of the source and destination blocks connected by the signal? Also, how can the port numbers (source and destination) be printed from the Command Window?
Accepted Answer
MathWorks Support Team
on 23 Jan 2019
The handle to a selected signal can be obtained using the 'find_system' command:
>> h_line = find_system(gcs,'FindAll','on','FollowLinks','on','type','line','Selected', 'on');
The names of the source and destination blocks with respect to the selected signal can be obtained using the 'get_param' command with the 'SrcBlockHandle' and 'DstBlockHandle' parameters:
>> source_block_handle = get_param(h_line, 'SrcBlockHandle');
>> source_block_name = get_param(source_block_handle, 'Name');
Similarly, the 'SrcPortHandle' and 'DstPortHandle' parameters can be used to obtain the port numbers associated with the selected signal:
>> source_port_handle = get_param(h_line, 'SrcPortHandle');
>> source_port_number = get_param(source_port_handle, 'PortNumber');
0 Comments
More Answers (0)
See Also
Categories
Find more on Prepare Model Inputs and Outputs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!