How to rename connections between blocks in Simulink

9 views (last 30 days)
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

Accepted Answer

stozaki
stozaki on 23 Sep 2020
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

More Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!