How can I connect 3 Simscape ports programmatically

2 次查看(过去 30 天)
Hello everyone,
Recently I am having a simulink problem:
I would like to connect 3 Simscape Electrical Ports programmatically.
The result should look something like this:
For that I wrote a MATLAB Code that should create the above:
simulink
open_system(new_system('sys'));
% Add Blocks
add_block('nesl_utility/Connection Port','sys/1');
add_block('nesl_utility/Connection Port','sys/2');
add_block('ee_lib/Passive/Capacitor','sys/C');
% Move Blocks
set_param('sys/1','position',[0,0,30,30]);
set_param('sys/C','position',[0,100,30,130]);
set_param('sys/2','position',[0,200,30,230]);
% Find Position
par1 = get_param('sys/1','PortConnectivity');
parC = get_param('sys/C','PortConnectivity');
par2 = get_param('sys/2','PortConnectivity');
pos1 = par1.Position;
posC1 = parC(1).Position;
posC2 = parC(2).Position;
pos2 = par2.Position;
% Connect Blocks
add_line('sys', [pos1;posC1]);
add_line('sys', [pos2;posC2]);
add_line('sys', [pos1;pos2]);
The problem is, that one connection is always missing, and with the above code I get this:
Is there any solution for this?

采纳的回答

Timo Dietz
Timo Dietz 2022-1-14
Hello,
you can directly connect via the port pin names, instead of using the position information:
add_line('sys', '1/RConn1', 'C/LConn1')
add_line('sys', '2/RConn1', 'C/RConn1')
add_line('sys', '1/RConn1', '2/RConn1')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Magnetic Elements 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by