在 Function Block Simulink 中使用 set_param 的 Mxarray 错误

Mxarray error using set_param in Function Block Simulink

我有一个有 3 层的模型:子系统 => 2 个子系统 => 1 个 Matlab 函数块(在两个父子系统中的每一个) 功能块的输入可以取值:1、2 或 3。 我有这个代码:

y = u;
coder.extrinsic('set_param','get_param','gcs');
parent = get_param(gcs,'parent');
parent2 = get_param(parent, 'parent');
Color = get_param(parent2, 'BackgroundColor');
if u == 3
     set_param(get_param(parent, 'parent'),'BackgroundColor','red');
elseif u == 2
    if Color == 'red'
    else
        set_param(get_param(parent, 'parent'),'BackgroundColor','orange');
    end
else
    if Color == 'red' || Color == 'orange'
    else
        set_param(get_param(parent, 'parent'),'BackgroundColor','green');
    end
end

解释

当块接收到 3 时,顶部子系统变为红色,2 => 橙色和 1 => 绿色

如果他已经是红色他就保持红色,如果他已经是橙色他可以是红色而不是绿色。

错误Expected either a logical, char, int, fi, single, or double. Found an mxArray. MxArrays are returned from calls to the MATLAB interpreter and are not supported inside expressions. They may only be used on the right-hand side of assignments and as arguments to extrinsic functions.

我不明白为什么 Color 不是字符串值,因为它源自 get_param 函数。

感谢帮助

它与 isequal() 一起工作

if isequal(Color,'red') || isequal(Color,'orange')