Alex44
Alex44

Reputation: 3855

Simulink Mask Editor: replace block

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:

Upvotes: 0

Views: 1017

Answers (1)

Navan
Navan

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

Related Questions