使用包含 MATLAB Function 模块的封装库子系统运行仿真并生成代码

导航模型

```function c = my_conv(a, b, shape) if shape == 1 c = conv(a, b, "full"); elseif shape == 2 c = conv(a, b, "same"); else c = conv(a, b, "valid"); end ```

从模型生成 C 代码

``` /* * Output and update for atomic system: * '<S1>/MATLAB Function' * '<S2>/MATLAB Function' */ void MLFB_model_MATLABFunction(const real_T rtu_a[2], const real_T rtu_b[5], real_T rty_c[6]) { int32_T b_k; int32_T i; for (i = 0; i < 6; i++) { rty_c[i] = 0.0; }```
``` for (i = 0; i < 2; i++) { for (b_k = 0; b_k < 5; b_k++) { int32_T tmp; tmp = i + b_k; rty_c[tmp] += rtu_a[i] * rtu_b[b_k]; } } }```

`my_conv_filter2` 实例使用不同函数，因为它使用不同输入。

``` /* Output and update for atomic system: '<S3>/MATLAB Function' */ void MLFB_model_MATLABFunction_p(const real_T rtu_a[3], const real_T rtu_b[3], real_T rty_c[5]) { int32_T i; for (i = 0; i < 5; i++) { rty_c[i] = 0.0; }```
``` for (i = 0; i < 3; i++) { rty_c[i] += rtu_b[i] * rtu_a[0]; rty_c[i + 1] += rtu_b[i] * rtu_a[1]; rty_c[i + 2] += rtu_b[i] * rtu_a[2]; } }```