Reputation: 3855
I want to change a block of a subsystem to be a built-in/Inport
or a built-in/Constant
in Matlab/Simulink 2016b.
disp(PortStat)
switch PortStat
case 'off'
if strcmp(get_param([gcb '/eng'],'BlockType'),'Inport')
disp('replace inport to constant')
replace([gcb '/eng'],'built-in/Inport','built-in/Constant')
get_param([gcb '/eng'],'BlockType')
replace_block([gcb '/eng'],'built-in/Inport','built-in/Constant')
get_param([gcb '/eng'],'BlockType')
end
case 'on'
if strcmp(get_param([gcb '/eng'],'BlockType'),'Inport')
disp('inport already exist')
end
if strcmp(get_param([gcb '/eng'],'BlockType'),'Constant')
disp('replace constant to inport')
replace([gcb '/eng'],'built-in/Inport');
end
end
switching the checkbox leads to the following output:
on
inport already exist
off
replace inport to constant
ans =
myModel/Subsys/eng
ans =
Inport
ans =
Inport
The BlockType does not change. But why?
Further information:
set_param(gcb, 'MaskSelfModifiable', 'on');
and the greyed out field Allow library block to modify its contents on the Initialization pane of the Mask editor is checked out.Upvotes: 0
Views: 1017
Reputation: 4477
The call to replace_block is not correct. replace_block takes a block type and the system in which the replacement occurs. For your case the call should like,
replace_block(gcb, 'Inport', 'Constant');
or
replace_block(gcb, 'Constant', 'Inport');
for the reverse case. BlockType is 'Constant' or 'Inport' and does not include 'built-in' as you see in your display. Additionally the above call will replace all blocks inside gcb that have the source block type. So you cannot use this function if you have multiple blocks with same block type but want to replace only one of them.
Upvotes: 1