How can I connect 3 Simscape ports programmatically

5 ビュー (過去 30 日間)
Ferdinand Grimm
Ferdinand Grimm 2022 年 1 月 14 日
回答済み: Timo Dietz 2022 年 1 月 14 日
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 Center および File ExchangeMagnetic Elements についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by