How can I connect 3 Simscape ports programmatically

5 vues (au cours des 30 derniers jours)
Ferdinand Grimm
Ferdinand Grimm le 14 Jan 2022
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?

Réponse acceptée

Timo Dietz
Timo Dietz le 14 Jan 2022
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')

Plus de réponses (0)

Catégories

En savoir plus sur Magnetic Elements dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by