Embedded matlab function中参数parameter的设置问题

本文探讨了在Embedded MATLAB Function中设置parameter的原因、方法及其理解。parameter用于从封装子系统的参数或MATLAB工作空间中以只读方式获取值。设置方法包括在编辑器中定义参数,并在Model Explorer中将其Scope设为parameter,使其在函数头部显示并允许测试。

   在embedded matlab function中,有四种类型数据(scope)与外界做交换:input、output、parameter和data store memory。

input和output是输入与输出,对应于函数的输入与输出参数,容易理解。data store memory暂时不予考虑。这次谈谈parameter的设置问题。

一.设置parameter的原因。

   简而言之,设置parameter是为了能让embedded matlab function能够从其父已封装子系统的参数或者matlab工作空间(workspace)中的变量以只读的方式获取值。

二.如何设置parameter。
  1.   在embedded matlab editor中函数首行中设置参数,但参数名称要与想要传递过来的的变量名称一致。即将parameter当做同名的input卸载function header中。
  2.    这时,我们要设置的参数就像一个input port一样显示在模块中。

     假如我们想要传递一个名为para的parameter,此时的editor中代码如下:

 

         模块的外观如下:

          

   3.   在embedded matlab editor中的菜单tool->Model Explorer中或tool->Edit Data/Port中其父系统的菜单View->Model Explorer(Ctrl-h)中更改其Scope为parameter,如下两图所示:

      

      

       4.   此时para已经是parameter了,观察block的外观,也没有para这个port了。

        

 

 

三.对于parameter的一些理解.

     parameter看起来好像是函数头部的输入参数一样(header of embedded matlab function)一样,这是为了与matlab中的function保持一致性。这样你就可以通过复制粘贴函数来测试函数了。

### Generating code into build folder: D:\新HMS\0_Customer\0_ASW\CT\CT_ert_rtw Logical indexing requires support of variable-sized arrays, which is currently disabled for code generation. Consider selecting the 'Support variable-size signals' option on the Configuration Parameters > Code Generation > Interface page. Function '输出/MATLAB Function' (#216.1270.1279), line 38, column 32: "temp_mask" Component:MATLAB Function | Category:Coder error Undefined function or variable 'valid_temps'. The first assignment to a local variable determines its class. Function '输出/MATLAB Function' (#216.1297.1308), line 39, column 16: "valid_temps" Component:MATLAB Function | Category:Coder error Undefined function or variable 'valid_temps'. The first assignment to a local variable determines its class. Function '输出/MATLAB Function' (#216.1413.1424), line 42, column 26: "valid_temps" Component:MATLAB Function | Category:Coder error Undefined function or variable 'median_temp'. The first assignment to a local variable determines its class. Function '输出/MATLAB Function' (#216.1458.1469), line 43, column 32: "median_temp" Component:MATLAB Function | Category:Coder error Errors occurred during parsing of MATLAB function 'CT/输出/MATLAB Function' Component:MATLAB Function | Category:Coder error Units '℃' specified for the 'Unit' field of Simulink.Signal object 'ETHCom_hcbottletempmaxtx' referenced by 'CT/输入信号解析/温度传感器器处理模块/Measuring Point/SignalConversion' are not defined in the Simulink unit database. Investigate 2 similar inconsistencies on Model Advisor Report. If you cannot use a unit that exists in the database, consider suppressing all units inconsistency warnings by setting the configuration parameter 'Units inconsistency messages' to 'none'. Component:Simulink | Category:Block warning ### Build procedure for model: 'CT' aborted due to an error. Errors occurred during parsing of MATLAB function 'CT/输出/MATLAB Function'
最新发布
12-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值