Documentation

Replace Code Generated from金宝appModels

This example shows how to replace generated code, using a code replacement library. Code replacement is a technique you can use to change the code that the code generator produces for functions and operators to meet application code requirements.

Prepare for Code Replacement

  1. Make sure that MATLAB®, Simulink®,Simulink Coder™, and a C compiler are installed on your system. Some code replacement libraries available in your development environment can also require Embedded Coder®.

    To install MathWorks®products, see the MATLAB installation documentation. If you have installed MATLAB and want to see which other MathWorks products are installed, in the Command Window, enterver.

  2. Identify an existing or create a Simulink model for which you want the code generator to replace code.

Choose a Code Replacement Library

If you are not sure which library to use, explore the available libraries.

Configure Code Generator To Use Code Replacement Library

  1. Configure the code generator to apply a code replacement library during code generation for the model. Do one of the following:

    • In the Configuration Parameters dialog box, on theCode Generation>Interfacepane, select a library for the代码替换库范围。

    • Set theCodeReplacementLibraryparameter at the command line or programmatically.

  2. 配置代码生成器仅生成代码(不构建可执行文件),因此您可以在构建可执行文件之前验证代码替换。做以下一个:

    • In the Configuration Parameters dialog box, on theCode Generationpane, selectGenerate code only.

    • Set theGenCodeOnlyparameter at the command line or programmatically.

Include Code Replacement Information In Code Generation Report

If you have an Embedded Coder license, you can configure the code generator to include a code replacement section in the code generation report. The additional information can help you verify code replacements.

  1. Configure the code generator to generate a report. In the Configuration Parameters dialog box, on theCode Generation>Reportpane, selectCreate code generation report. Consider having the report open automatically. SelectOpen report automatically.

  2. Include the code replacement section in the report. SelectSummarize which blocks triggered code replacements.

Generate Replacement Code

Generate C/C++ code from the model and, if you configured the code generator accordingly, a code generation report. For example, in the model window, pressCtrl+B.

The code generator produces the code and displays the report.

Verify Code Replacements

Verify code replacements by examining the generated code. It is possible that code replacement behaves differently than you expect. For example, data types that you observe in the code generator input might not match what the code generator uses as intermediate data types during an operation.

相关话题

Was this topic helpful?