How to rename connections between blocks in Simulink

7 visualizaciones (últimos 30 días)
Robin
Robin el 23 de Sept. de 2020
Comentada: Robin el 23 de Sept. de 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

Respuesta aceptada

stozaki
stozaki el 23 de Sept. de 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 comentario
Robin
Robin el 23 de Sept. de 2020
Hello stozaki, your solution is working very good. Thank you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by