Connect two simulink lines programatically

9 次查看(过去 30 天)
Hi,
I have a need to remove all goto-from block pair (requirement for some project) and perform the connections with lines.
I can make a script that removes all goto-from blocks and I can basically track source for each goto and destination for each from which I can thn connect with add_line, but this appreach is awkward and has certain implementation problems (immagine from block that feeds some things one of which is some other goto block).
What I ould like to do is programatically connect the lines that connect from and to those goto-from pairs. i.e. I remove the blocks with delete_block and then would like to connect the wires that were previously connected to each pair. add_line doesn't seem to accept line handles as argument. So the question is:
How do I programatically connect to simulink lines?

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2020-6-17
%%
Model='ex_goto_tag_visibility_block';
open_system(Model);
Block=[Model,'/GotoGlobal'];
PC=get_param(Block,'PortConnectivity');
P1=PC(1).Position;
delete_block(Block);
Block=[Model,'/From'];
PC=get_param(Block,'PortConnectivity');
P2=PC(1).Position;
delete_block(Block);
add_line(Model,[P1;P2])

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by