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

22 views (last 30 days)
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.

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 8 Jun 2012
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 Comments
Kaustubha Govind
Kaustubha Govind on 11 Jun 2012
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 on 13 Jun 2012
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.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!