How to rename connections between blocks in Simulink

6 Ansichten (letzte 30 Tage)
Robin
Robin am 23 Sep. 2020
Kommentiert: Robin am 23 Sep. 2020
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

Akzeptierte Antwort

stozaki
stozaki am 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
  1 Kommentar
Robin
Robin am 23 Sep. 2020
Hello stozaki, your solution is working very good. Thank you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by