首页 > 解决方案 > Simulink:在停止时引用掩码块

问题描述

我创建了一个动态掩码块,根据我的掩码参数,我删除其中一条线(我们称之为 myFirstLine)并添加另一条线(我们称之为 mySecondLine)。当我第一次运行模拟时,一切都很好。但是,在第二次运行中,模拟抱怨它无法运行掩码块的初始化。这似乎是正确的,因为它在第一次模拟运行中删除了 myFirstLine,而在第二次模拟运行中没有要删除的 myFirstLine。我的掩码块是库块。所以,我想知道在模拟停止后是否可以将掩码块刷新为其默认值。

作为 MWE,请考虑我有一个带有参数“numBLK”的掩码块。我的掩码块初始化中有以下代码:

if numBLK > 1
     delete_line('myMaskBLK','myBLK_1/1','myOut/1');
     add_block('simulink/Math Operations/Matrix Concatenate','myMaskBLK/myMux','NumInputs','numBLK','ConcatenateDimension','1');
     add_line('myMaskBLK','myBLK_1/1','myMux/1');
     for counter = 2 : numBLK
          add_block('myMaskBLK/myBLK',strcat('myMaskBLK/myBLK',num2str(counter)));
          add_line('myMaskBLK',strcat('myMaskBLK/myBLK',num2str(counter)),strcat('myMux/',num2str(counter)));
     end
end

标签: simulinkmaskingsimulink-library

解决方案


推荐阅读