Get SrcPortName from only line handle (without block handle)

조회 수: 4 (최근 30일)
Ewela
Ewela 2021년 11월 10일
답변: Ayush Modi 2024년 3월 7일
How can I obtain the SrcPortName from line handle?
line_handle = find_system(gcs,'SearchDepth', 1, 'FindAll', 'on', 'type', 'line');
handleSourcePort = get_param(line_handle, 'SrcPortHandle')
portname = get(handleSourcePort,'Name')
I got empty variable portname =[], but it should be 'Out1'.
Thank you in advance for help.

답변 (1개)

Ayush Modi
Ayush Modi 2024년 3월 7일
Hi Ewela,
The provided code works for me and I am able to get the value in portname. However, playing around with it, I found out that "portname" would be returned empty if:
  • simulation model is closed - "gcs" returns the path name of the current system. If the simulation model is not open, gcs will return Null. Thus, portname will be empty.
  • simulation model is not saved - Ensure that the latest model is saved where the line name is set.
Furthermore, If there are multiple connections in the simulation model, brace indexing would be needed to get the name of a particular Source port handle. Here is the code to demonstrate the same:
line_handle = find_system(gcs,'SearchDepth', 1, 'FindAll', 'on', 'type', 'line');
handleSourcePort = get_param(line_handle, 'SrcPortHandle')
portname = get(handleSourcePort{1},'Name')
Hope this helps!

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by