Any way to figure out what your blocks are connected to in a model?

조회 수: 21 (최근 30일)
inPorts = find_system(modelName,'SearchDepth',2,'BlockType','Inport');
outPorts = find_system(modelName,'SearchDepth',2,'BlockType','Outport');
I use that to get the Inport and Outport blocks in my model, but is there any way to see what they're connected to/from. I want to find out what's connected to my Outport block. I didn't know if I could trace it through the line that's connected to it to a Sum/Add block, or any other type of block.

채택된 답변

Kaustubha Govind
Kaustubha Govind 2012년 6월 8일
Get the block's port handles using:
ph = get_param(gcb, 'PortHandles')
Examine ph.Inport and ph.Outport to get the handles to the block(s) connected at the input/output.
  댓글 수: 2
Kaustubha Govind
Kaustubha Govind 2012년 6월 11일
1) outPorts is a cell-array, so you need to index into it using curly brackets: outPorts{i}
2) I think the LConn and RConn fields are only for Physical Modeling ports, so that won't work unless you have SimScape blocks.
3) Sorry, I just realized PortConnectivity is a better option than PortHandles in your case. I wrotea short sample, but you may need to modify/clean-up:
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');
Kaustubha Govind
Kaustubha Govind 2012년 6월 13일
Lucas: The number after the slash is just the port number. For the source block, it is the output port number and for the destination block, it is the input port number.

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by