simulink 代码生成 2020a

首先建立一个简单的模型

在这里插入图片描述

进行一下设置

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

快捷键 ctrl+B ,编译

此时生成的代码:


/*
 * File: untitled.c
 *
 * Code generated for Simulink model 'untitled'.
 *
 * Model version                  : 1.0
 * Simulink Coder version         : 9.3 (R2020a) 18-Nov-2019
 * C/C++ source code generated on : Sun Jul 19 21:00:16 2020
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "untitled.h"
#include "untitled_private.h"

/* External inputs (root inport signals with default storage) */
ExtU_untitled_T untitled_U;

/* External outputs (root outports fed by signals with default storage) */
ExtY_untitled_T untitled_Y;

/* Real-time model */
RT_MODEL_untitled_T untitled_M_;
RT_MODEL_untitled_T *const untitled_M = &untitled_M_;

/* Model step function */
void untitled_step(void)
{
  /* Outport: '<Root>/Out1' incorporates:
   *  Inport: '<Root>/In1'
   *  Inport: '<Root>/In2'
   *  Sum: '<Root>/Sum'
   */
  untitled_Y.Out1 = untitled_U.In2 + untitled_U.In1;
}

/* Model initialize function */
void untitled_initialize(void)
{
  /* (no initialization code required) */
}

/* Model terminate function */
void untitled_terminate(void)
{
  /* (no terminate code required) */
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */




有用的:

void untitled_step(void)
{
  /* Outport: '<Root>/Out1' incorporates:
   *  Inport: '<Root>/In1'
   *  Inport: '<Root>/In2'
   *  Sum: '<Root>/Sum'
   */
  untitled_Y.Out1 = untitled_U.In2 + untitled_U.In1;
}

参数修改

参数配置

在这里插入图片描述

  • 以下几张图的位置有变,以上一张为准

输入设置为:

在这里插入图片描述

通过上方按钮添加向相应参数和信号

在这里插入图片描述

输出设置为:

在这里插入图片描述

参数k设置为:

在这里插入图片描述
注: 参数K要有初始值
在这里插入图片描述

参数关联

双击连线:更改为之前的,并右键设置property
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
k直接填就行在这里插入图片描述

编译完后,最终效果:


/*
 * File: gen3.c
 *
 * Code generated for Simulink model 'gen3'.
 *
 * Model version                  : 1.1
 * Simulink Coder version         : 9.3 (R2020a) 18-Nov-2019
 * C/C++ source code generated on : Sun Jul 19 21:47:19 2020
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "gen3.h"
#include "gen3_private.h"

/* Exported block signals */
real_T z;                              /* '<Root>/Gain' */

/* Real-time model */
RT_MODEL_gen3_T gen3_M_;
RT_MODEL_gen3_T *const gen3_M = &gen3_M_;

/* Model step function */
void gen3_step(void)
{
  /* Gain: '<Root>/Gain' incorporates:
   *  Inport: '<Root>/In1'
   *  Inport: '<Root>/In2'
   *  Sum: '<Root>/Sum'
   */
  z = (x + y) * k;
}

/* Model initialize function */
void gen3_initialize(void)
{
  /* (no initialization code required) */
}

/* Model terminate function */
void gen3_terminate(void)
{
  /* (no terminate code required) */
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */


有用的

void gen3_step(void)
{
  /* Gain: '<Root>/Gain' incorporates:
   *  Inport: '<Root>/In1'
   *  Inport: '<Root>/In2'
   *  Sum: '<Root>/Sum'
   */
  z = (x + y) * k;
}

  • 5
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值