Matlab编码器:“所有输入必须恒定". [英] Matlab coder: "All inputs must be constant"

查看:457
本文介绍了Matlab编码器:“所有输入必须恒定".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Matlab Coder将此代码转换为C ++:

I'm using Matlab Coder to convert this code to C++:

fs = 50;
[b,a] = butter(3,0.5/(fs/2),'high');
...
% Other code using fs

然后,我得到这个错误:所有输入必须恒定".

Then, I get this error: "All inputs must be constant".

如果我这样做:[b,a] = butter(3,0.5/(50/2),'high');,它可以工作.

If I do: [b,a] = butter(3,0.5/(50/2),'high');, it works.

我发现了这篇文章:常量和Matlab编码器

所以我尝试了:

fs = 50;
[b,a] = coder.const(@butter,3,0.5/(fs/2),'high');

但是它仍然报告相同的错误.我该如何解决?

But it still reports the same error. How can I fix this?

推荐答案

定义具有常量值的类属性

在ConstInput.m

In ConstInput.m

classdef ConstInput
   properties (Constant)
      fs = 50;
   end
end

然后将fs重命名为ConstInput.fs. (很遗憾,Shift+Enter无法正常工作.也许此链接对

Then rename fs as ConstInput.fs. (Unfortunately, Shift+Enter does not work. Maybe this links helps about changing variable names.)

这篇关于Matlab编码器:“所有输入必须恒定".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆