How to obtain the source and destination block names and port numbers connected by a signal in Simulink?
12 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2019-1-23
回答: MathWorks Support Team
2019-3-27
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
2019-1-23
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Prepare Model Inputs and Outputs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!