如何将开关状态从m文件传输到Simulink块?

时间:2019-11-07 10:03:50

标签: matlab simulink

我想控制m文件的切换。我想使用'if action'块来制作它,而'if action'块由Matlab函数控制。 Matlab函数的输入来自m文件。

Simulink如下: enter image description here

Matlab函数的代码如下:

function y = fcn_test(x1, x2)

y = x1 + x2;

现在,我想从m文件传输Matlab函数的输入,例如x1和x2。 m文件如下:

clc

global x1
global x2
x1 = 1;
x2 = 2;

a = fcn_test(x1, x2);

disp(a)

错误为Simulink model 'fcn_test' was called with incorrect number of arguments。那么代码的问题是什么?

1 个答案:

答案 0 :(得分:0)

您有一个模型和一个名为fcn_test的m文件。您实际上是在调用描述为here的模型函数,而不是您的m代码。重命名两者之一。