In the shared code, the line PH_AddCell{v}=get(AddCell(v),'PortHandles'); only stores port handles for blocks in the current column, which gets overridden with each iteration as i changes. To maintain a matrix of handles, use:
PH_AddCell{v,i}=get(AddCell(v),'PortHandles');
Assumptions for the blocks CELL_Unit/CELL 1 and CELL_Unit2/CELL 1 are as follows:
- In CELL_Unit/CELL 1, port 1 is positive (pos) and port 2 is negative (neg).
- In CELL_Unit2/CELL 1, port 1 is negative (neg) and port 2 is positive (pos).
- Port locations are set to "Left" for both pos and neg in these blocks.
The the two additional connections to the cell array, can finally be indroduced as shown below:
Plus_2_Cell = find_system(mdl,'LookUnderMasks','All','FindAll','on','Name','POS');
PH_plus2Cell=get(Plus_2_Cell,'PortHandles');
add_line(mdl,PH_plus2Cell.RConn,PH_AddCell{1,1}.LConn(1,1), 'Autorouting','on');
add_line(mdl,PH_AddCell{numRows,1}.LConn(1,2),PH_AddCell{numRows,2}.LConn(1,2), 'Autorouting','on');
Here's the final result:
For a quick start guide on programmatically modeling, visit: