Matlab coder: “All inputs must be constant”

浪子不回头ぞ 提交于 2020-02-25 06:28:06

问题


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".

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

I found this post: Constants and Matlab Coder

So I tried:

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?


回答1:


Define Class Properties with Constant Values

In ConstInput.m

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

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



来源:https://stackoverflow.com/questions/60202957/matlab-coder-all-inputs-must-be-constant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!