MATLAB Simulink embedded function variable setting

To generate embeddable code, the Embedded MATLAB Function blockrelies on an analysis that determines the size, class, and complexityof each variable. This analysis imposes the following restrictions:

  • The first assignment to a variabledefines its, size, class, and complexity.

    See Working with Variables inthe Embedded MATLAB documentation.

  • Generally, you cannot reassign variable propertiesafter the initial assignment except when using variable-size dataor reusing variables in the code for different purposes.

    See When You Can Reassign Properties in Embedded MATLAB Code inthe Embedded MATLAB documentation

    In the MATLAB language, variables change their propertiesdynamically so you can use the same variable to hold a value of anyclass, size, or complexity. For example, the following code worksin MATLAB:

    if(c>0)
      x = int8(0);
    else
      x = [1 2 3];
    end
    % The type of 'x' here depends on 
    % the value of 'c'. MATLAB handles this.
    disp(x); 

    In Embedded MATLAB functions, you must assign variablesexplicitly to have a specific class, size, and complexity before usingthem in operations or returning them as outputs . For more information,see Assign Variables Explicitly Before Using Them

    When You Can Reassign Properties in Embedded MATLAB Code

    There are certain cases when you can reassign a variable witha value of different class, size, or complexity:

    • Dynamically sized variables

      A variable can hold values that have the same class and complexitybut different sizes. If the size of the initial assignment is notconstant, Embedded MATLAB makes a variable dynamically sized.For more information, see Working with Variable-Size Data.

    • Variables reused in the code for different purposes

      If a variable is reused in the code in such a way that it holdsvalues of different class, size, or complexity in different partsof your source code, Embedded MATLAB attempts to rename the variablein each part of the code to create multiple independent variables.For more information, see Reusing the Same Variable with Different Properties.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值