How to rename connections between blocks in Simulink

9 ビュー (過去 30 日間)
Robin
Robin 2020 年 9 月 23 日
コメント済み: Robin 2020 年 9 月 23 日
How to rename connections between blocks in Simulink. Below is code to rename GotoTag in Blocks. But also to rename connection between blocks is required. In attachment is the corresponding Simulink model with a "From" and a "Goto" block that should be renamed with the code below. Additionally is a "Constant" block as dummy connected to the "Goto" block. This connection to "Goto" block should also get the new name of "Goto" block.
CurrentName = "A";
RequiredName = "B";
b1 = Simulink.findBlocks('model','GotoTag',CurrentName);
for i=1:length(b1)
set_param(b1(i),'GotoTag',RequiredName);
end

採用された回答

stozaki
stozaki 2020 年 9 月 23 日
Hello
I have attached a model that is easier to understand.
Please try following script.
CurrentName = "A";
RequiredName = "B";
b1 = Simulink.findBlocks("model","GotoTag",CurrentName);
for i=1:length(b1)
set_param(b1(i),"GotoTag",RequiredName);
blkType = get_param(b1(i),"BlockType"); % get block type
potH = get_param(b1(i),"PortHandles"); % get porthandle
if strcmp(blkType,"Goto")
lineH = get_param(potH.Inport,"Line"); % get LineHandle
if isequal(lineH,-1)
% not connect
else
set_param(lineH,"Name",RequiredName);
end
elseif strcmp(blkType,"From")
lineH = get_param(potH.Outport,"Line"); % get LineHandle
if isequal(lineH,-1)
% not connect
else
set_param(lineH,"Name",RequiredName);
end
else
% nop
end
end
stozaki
  1 件のコメント
Robin
Robin 2020 年 9 月 23 日
Hello stozaki, your solution is working very good. Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by