add_line connection for to column cells
Show older comments
Hi there,
While creating column Cells connections, last cell in each column still not connected...stayed unconnected.
I wonder if someone can assist to solve this problem.
please see shared Matlab code (file.m) and picture (marked in red line)
Thanks for help
Tommy
open_system('Module_arc')
mdl = 'Module_arc';
bat_rec_model = find_system(mdl,'FindAll','on','Name','Module_arc');
%%% add Cell - basic CELL_unit:
for i=1:2 %% set two columns
colPos = 200; %% spaces between columns
for v=1:4 %% loop for 13 cells per column
nl=num2str(v + 4*(i-1));
if i==1
AddCell(v) = add_block('CELL_Unit/CELL 1', [mdl,'/CELL ',nl]);
else
AddCell(v) = add_block('CELL_Unit2/CELL 1', [mdl,'/CELL ',nl]);
end
posc = get(AddCell(v),'Position');
set(AddCell(v),'Position',posc + [100+(i-1)*colPos 120*(v-1)-45 100+(i-1)*colPos 120*(v-1)-45])
PH_AddCell{v}=get(AddCell(v),'PortHandles');
%%% connect minus to plus ports:
if v>1
add_line(mdl,PH_AddCell{v-1}.LConn(2),PH_AddCell{v}.LConn(1),'Autorouting','on');
end
end
switch i
case 2
Minus_2_Cell = find_system(mdl,'LookUnderMasks','All','FindAll','on','Name','NEG');
PH_minus2Cell=get(Minus_2_Cell,'PortHandles');
Neg_port= add_line(mdl,PH_minus2Cell.RConn,PH_AddCell{1}.LConn(1),'Autorouting','on');
case 1
Plus_2_Cell = find_system(mdl,'LookUnderMasks','All','FindAll','on','Name','POS');
PH_plus2Cell=get(Plus_2_Cell,'PortHandles');
Pos_port= add_line(mdl,PH_plus2Cell.RConn,PH_AddCell{1}.LConn(1), 'Autorouting','on');
end
end
Accepted Answer
More Answers (1)
Hi Tommy,
The last cells are not connected as you want as shown in the image because you have not added it in your code. The key is simply:
- Store the handle of the bottom cell in each column (AddCell(4)) when you finish creating that column.
- After the loop, use one add_line to connect the negative port of column1’s bottom cell to the positive port of column2’s bottom cell.
open_system('Module_arc')
mdl = 'Module_arc';
bat_rec_model = find_system(mdl,'FindAll','on','Name','Module_arc');
% keep track of the bottom cell in each column:
bottomCellCol1 = [];
bottomCellCol2 = [];
%%% add Cell - basic CELL_unit:
% your code...................
switch i
case 2
Minus_2_Cell = find_system(mdl,'LookUnderMasks','All','FindAll','on','Name','NEG');
PH_minus2Cell=get(Minus_2_Cell,'PortHandles');
Neg_port= add_line(mdl,PH_minus2Cell.RConn,PH_AddCell{1}.LConn(1),'Autorouting','on');
bottomCellCol1 = AddCell(4); % "CELL 4"
case 1
Plus_2_Cell = find_system(mdl,'LookUnderMasks','All','FindAll','on','Name','POS');
PH_plus2Cell=get(Plus_2_Cell,'PortHandles');
Pos_port= add_line(mdl,PH_plus2Cell.RConn,PH_AddCell{1}.LConn(1), 'Autorouting','on');
bottomCellCol2 = AddCell(4); % "CELL 8"
end
end
% Connect NEG port of CELL 4 to POS port of CELL 8
PH_col1Cell4 = get(bottomCellCol1, 'PortHandles'); % bottom of column 1
PH_col2Cell4 = get(bottomCellCol2, 'PortHandles'); % bottom of column 2
add_line(mdl, PH_col1Cell4.LConn(2), PH_col2Cell4.LConn(1), 'Autorouting','on');
Categories
Find more on Additional Math and Discrete in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




