Simulink Mask Editor:替换块

时间:2017-05-01 00:33:14

标签: matlab simulink

我想在Matlab / Simulink 2016b中将子系统的块更改为built-in/Inportbuilt-in/Constant

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

切换复选框会导致以下输出:

on
inport already exist
off
replace inport to constant

ans =
myModel/Subsys/eng

ans =
Inport

ans =
Inport

BlockType 不会更改。但为什么呢?

更多信息:

  • Syubsystem不是库对象。
  • 我在掩码编辑器 Initialization 窗格中运行set_param(gcb, 'MaskSelfModifiable', 'on');和灰色字段允许库块修改其内容 >已签出。

1 个答案:

答案 0 :(得分:1)

对replace_block的调用不正确。 replace_block采用块类型和发生替换的系统。对于你的情况,电话应该是,

replace_block(gcb, 'Inport', 'Constant');

replace_block(gcb, 'Constant', 'Inport');

相反的情况。 BlockType为“常量”或“输入”,并且不包括您在显示屏中看到的“内置”。另外,上面的调用将替换gcb中具有源块类型的所有块。因此,如果您有多个块具有相同的块类型但只想替换其中一个块,则无法使用此函数。