无法在Matlab编码器中传递文字常量

cannot pass a literal constant in Matlab Coder

本文关键字:文字 常量 编码器 Matlab      更新时间:2023-10-16

我正在使用Matlab Coder生成C++代码。它在所示代码的最后一行给出一个错误:

function [Xs Ys]=sc(X, Y, r)
...
xGauss=gausswin(2*r+1,5));

如果是类似的东西就好了

xGauss=gausswin(11,5));

所以我尝试了两种方法,一种是

xGauss=coder.const(@gausswin,2*r+1,5); 

但它说"coder.const是未定义的"。另一种方法是放置编码器。变量r为常量,但它再次失败。在windows上,它是"coder.Constant"类不支持代码生成。在Linux上,它的"coder.Constant"不是支持的枚举。对于代码生成,枚举必须继承自"int32"或"Simulink.IntEnumType"。"如何解决此问题?"?

我用代替gausswin解决了这个问题

function w = gausswin_2(L, a)
N = L-1;
n = (0:N)'-N/2;
w = exp(-(1/2)*(a*n/(N/2)).^2);
end