How to obtain the source and destination block names and port numbers connected by a signal in Simulink?

12 次查看(过去 30 天)
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?

采纳的回答

MathWorks Support Team
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 个)

类别

Help CenterFile Exchange 中查找有关 Prepare Model Inputs and Outputs 的更多信息

标签

尚未输入任何标签。

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by