常数和Matlab编码器 [英] Constants and Matlab Coder

查看:132
本文介绍了常数和Matlab编码器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Matlab Coder中运行时,某些函数要求输入必须为常量. 我希望找到一种在输入之前将输入声明为常量的方法,作为有问题的情况的示例:

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);

这将返回错误所有输入必须恒定"

如何将 x和y声明为常数,以便butter()感到高兴?我尝试了许多解决方案,但不幸的是,没有找到真正令人满意的东西.如果可以使用命令行操作coder.newtype('constant',x),它将简化所有操作.

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.

推荐答案

在函数中使用coder.const,以便函数butter知道您正在传递常量输入.可在此处获得该文档.

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);

注意:您无法在生成的代码中更改x/y的值.您可以分别更改xy,但不能更改两个数字的比率.

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.

这篇关于常数和Matlab编码器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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