MATLAB:Simulink 问题 "does not support code generation"

MATLAB: Issue with Simulink "does not support code generation"

我在 Simu 上有类似于下面的框图link,它看起来相当混乱,尤其是随着块数量的增加。

我想用功能块替换 3 点求和块,同时保持相同的输出。

首先我将代码放在函数块中:

function y = fcn(u)
   sys1 = tf(0.5,[1 0 0 4]);
   sys2 = tf([3 0.5],[1 0 15]);
   sys3 = tf(1,[1 1]);
y = sys1 + sys2 + sys3;

然而,我遇到了一个错误,说 Simulink 不支持代码生成。

"The 'tf' class does not support code generation."

然后我在这里遇到了类似的问题:https://nl.mathworks.com/matlabcentral/answers/74770-is-there-any-way-to-disable-code-generation-in-simulink

我正在尝试实现一个外部函数或 'wrapper function' 有一些困难。我创建了一个名为 myWrapper.m 的新脚本,其中包含相同的代码:

function y = myWrapper(u)
   sys1 = tf(0.5,[1 0 0 0 4]);
   sys2 = tf([3 5],[1 0 15]);
   sys3 = tf(1,[1 1]);
y = sys1 + sys2 + sys3;

并将 MATLAB 函数编辑为:

function y1 = fcn(u1)

y1 = myWrapper(u1);

错误仍然存​​在。

我想以某种方式从 MATLAB Function 块访问 myWrapper.m 文件。关于如何做到这一点的任何指示?按照之前给出的 link 和 official docs 我在我的 MATLAB 函数块中得到了这样的结果:

function y1 = fcn(u1)coder.extrinsic('myWrapper')

y1 = myWrapper(u1);

上面的最后一段代码在语法上不正确,我不知道应该如何完成。 MATLAB 自动将上述代码更正为:

function y1 = fcn(u1,coder,extrinsic, myWrapper )

y1 = myWrapper(u1);

这不是我想要的。

任何提示 and/or 关于如何做到这一点的建议将不胜感激。

两年前在 MathWorks 论坛 here 上提出了类似的问题,但没有得到回应。

我正打算解决这个问题,但完全错了。感谢一些有用的评论,我意识到为了替换求和块,必须 NOT 删除馈入求和块的传递函数块。

MATLAB 函数不支持代码生成(这是正确的),因此可以在其中实现传递函数。这就是为什么块简单地按如下方式输入 MATLAB 函数的原因。

脚本将非常简单:

function y1 = fcn(u1, u2, u3)

   x = (u1 + u2 +u3);
   y1 = x;

end