Constants and Matlab Coder

橙三吉。 提交于 2019-12-12 11:26:41

问题


Some functions requires the input to be a constant, when run in Matlab Coder. I wish to find a way to declare the input as a constant before it is input as an example for the problematic situation:

  function foo = subsubfunction(x,y)            
      [B,A]=butter(1,x/y);

This will return the error 'All inputs must be constant'

How do I declare x and y as constants so that butter() gets happy? I have tried many solutions and unfortunately not found anything really satisfying. If the command line operation coder.newtype('constant',x) could be used it would simplify everything.


回答1:


Use coder.const in the function, so that the function butter knows you are passing a constant input. The documentation is available here.

 function foo = subsubfunction(x,y)            
  [B,A]=coder.const(@butter,1,x/y);

Note: You cannot change the value of x/y in the generated code. You could individually change x and y, but not the ratio of the two numbers.



来源:https://stackoverflow.com/questions/9467573/constants-and-matlab-coder

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