How to rename connections between blocks in Simulink

4 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by