Main Content

本页的翻译已过时。点击此处可查看最新英文版本。

原型构建和调试中的数据访问

在生成的代码中配置数据的可访问性

您在模型中创建的信号、状态和模块参数在生成的代码中显示为变量。您可以控制代码声明和定义这些变量的方式。

  • 管理对信号数据的访问并指定参数可调性。

  • 提高代码的可读性和可追溯性。

  • 通过为声明和定义指定标识符和文件位置,简化将生成的代码与您自己的代码进行集成的过程。

  • 通过减少内存使用量并指定数值数据类型,生成高效的代码。

主题

生成的代码中的数据存储

生成的代码如何存储内部信号、状态和参数数据

为了根据输入数据计算输出数据,生成的代码必须在内存中存储一些内部数据,例如模块状态数据和非标量参数数据。

Data Structures in the Generated Code

The code generator uses data structures in the generated code to describe the model fully and store data, such as signal and states.

在生成的代码中使用枚举数据

枚举数据是指仅限于一组有限值的数据。在生成的代码中创建枚举。

Data Stores in Generated Code

Use a data store to explicitly model a piece of shared global data in the generated code.

Parameter Data Types in the Generated Code

Optimize the generated code and generate code for specific processors by controlling the data types that store parameter data in computer memory.

Share Data Between Code Generated from Simulink, Stateflow, and MATLAB

Define data shared between Simulink, Stateflow, and MATLAB.

Optimize Generated Code Using Fixed-Point Data with Simulink, Stateflow, and MATLAB

Generate fixed-point code in Simulink®, Stateflow®, and MATLAB®.

Optimize Speed and Size of Signal Processing Algorithm by Using Fixed-Point Data

Model a fixed-point acoustic noise canceller.

数组布局

Code Generation of Matrices and Arrays

Work with code that the code generator produces for matrices and arrays.

Generate Row-Major Code for S-Functions

Enable existing S-functions for row-major code generation by specifying the array layout.

Generate Row-Major Code for Model That Contains a MATLAB Function Block

Use coder.rowMajor inside the MATLAB Function block to generate row-major code.

Column-Major Layout to Row-Major Layout Conversion of Models with Lookup Table Blocks

Convert existing column-major model to row-major for code generation.

Row-Major Algorithms for Row-Major Array Layout

Generate code by using the row-major and column-major algorithms for row-major array layout.

Interpolation Algorithm for Row-Major Array Layout

Simulate and generate code by using the interpolation algorithm for row-major and column-major array layout.

Interpolation with Subtable Selection Algorithm for Row-Major Array Layout

Simulate and generate code by using the interpolation with subtable selection algorithm for row-major and column-major array layout.

Direct Lookup Table Algorithm for Row-Major Array Layout

Simulate and generate code by using the Direct Lookup Table algorithm for row-major and column-major array layout.

在执行期间访问数据

Access Signal, State, and Parameter Data During Execution

As you iteratively develop a model, capture output signal and state data that model execution generates. Tune parameter values during execution to observe results on the outputs.

Preserve Variables in Generated Code

As you iteratively develop a model, you can tune block parameter values during simulation or execution of generated code to observe the results on signal and state values.

Switch Between Sets of Parameter Values During Simulation and Code Execution

Switch between independent sets of values for the same block parameters by storing the sets in an array of structures.

在生成的代码中创建可调标定参数

在生成的代码中创建可在快速原型和标定过程中访问的可调参数数据。

Reuse Parameter Data in Different Data Type Contexts

Reuse parameter data by creating a Simulink.Parameter object or numeric MATLAB variable that you can use in different data type contexts.

Limitations for Block Parameter Tunability in Generated Code

Limitations can prevent a block parameter from appearing in the generated code as tunable, which means you cannot interact with the parameter value after compiling the code.

Control Signal and State Initialization in the Generated Code

Generate code that enables you to store tunable initial conditions in memory, for example, for modeling a system that shuts down and restarts.

Initialization of Signal, State, and Parameter Data in the Generated Code

To match the numerics of a simulation in Simulink, the generated code assigns initial values to global data, especially for block states and parameters.

Organize Data into Structures in Generated Code

Create structures of signal, state, and parameter data in the generated code.