Use add_line on a line?

조회 수: 12 (최근 30일)
Lucas
Lucas 2012년 6월 12일
I was wondering if you could get a handle from a line and draw a line from that to something else. Kaustubha helped me with the code below:
pc = get_param(outPorts{i}, 'PortConnectivity');
srcBlk = get_param(pc.SrcBlock, 'Name');
srcParent = get_param(pc.SrcBlock, 'Parent')
add_line(srcParent, [srcBlk '/1'], 'Out2/1', 'autorouting', 'on');
but if you have a sub system with 6 outports and you want to tie a line from each of them, the code above gets the previous block (subsystem) and ties a line from there to a new block. But it always ties a line from the first output, when I want one from each. So I if it’s possible to get a handle to a line, if you could use it as the source parameter in add_line.

채택된 답변

Albert Yam
Albert Yam 2012년 6월 12일
I don't know if there is another way, and I would like to know. This is my work around, it can get ugly, but works. I call it "x+1"
in_src = get_param(inblock, 'PortConnectivity');
in_src =in_src.Position;
add_line(sys,[in_src;in_src(1)+1 in_src(2)]); %draws a line from x to x+1
in_src =[in_src(1)+1 in_src(2)]; % save that location as source
outN = get_param(outNblock, 'PortConnectivity');
outN = outN.Position;
add_line(sys,[in_src;outN]);
So it technically works by drawing lines to position, rather than the block itself. You might get an unconnected line, but there is a script for that.
If there is better solution, I too would like to know.
  댓글 수: 1
Albert Yam
Albert Yam 2012년 6월 12일
You can use the block handle as a reference for that block, but if you want a name.
BlockName = get_param(handle,'Name');
Also,
<http://www.mathworks.com/matlabcentral/fileexchange/12352-delete-unconnected-lines>

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Chiara
Chiara 2013년 6월 4일
How can I specify left or right port to connect?
In my case,
in_src=get_param('new/source1', 'PortConnectivity')
gives a 2x1 struct array with fields: Type Position SrcBlock SrcPort DstBlock DstPort
Please tell me if I am wrong:
Where you wrote:
in_src =in_src.Position;
I should write:
in_src =in_src(1).Position; %for LConn1
in_src =in_src(2).Position; %for RConn1
and the same for outN. right?

카테고리

Help CenterFile Exchange에서 View and Analyze Simulation Results에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by