Main Content

データの表現とアクセス

外部コードとの統合を簡単にして対話機能と計測をサポートするためのデータ表現の設定

モデル内で作成した信号、ステートおよびブロック パラメーターは、生成されたコード内で変数として現れます。これらの変数をコード内で宣言および定義する方法を制御します。

  • メモリ使用量を減らし、数値データ型を指定することによって、効率的なコードを生成します。データ型の命名、定義および使用方法を制御します。

  • 識別子および宣言と定義のファイル配置を指定することで、生成されたコードと独自のコードを容易に統合できるようになります。

  • 信号データへのアクセスを管理し、パラメーターの調整可能性について指定します。

  • 信号とパラメーター データを構造体にパッケージ化します。

  • コードの可読性とトレーサビリティを高めます。

トピック

生成されたコード内のストレージ

How Generated Code Stores Internal Signal, State, and Parameter Data

To calculate output data from input data, the generated code must store some internal data in memory, such as block state data and nonscalar parameter data.

Standard Data Structures in the Generated Code

The generated code stores data, such as signals and states, in global structures. Use the structures to access and integrate with the data.

Use the Real-Time Model Data Structure

The real-time model data structure describes the generated model code and enables your code to interact with the generated code.

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.

Generate Local Variables with Localizable Storage Class

For signals, if possible, generate variables that are local to functions rather than in global storage. Generating local variables prevents the code generator from implementing optimizations that remove these variables from the generated code. Local variables improve observability, readability, and are helpful in debugging the generated code.

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

Define data shared between Simulink, Stateflow, and MATLAB.

Air-Fuel Ratio Control System with Fixed-Point Data

This example shows how to generate and optimize the code for a fixed-point air-fuel ratio control system designed with Simulink® and Stateflow®. For a detailed explanation of the model, see:

配列のレイアウト

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.

Dimension Preservation of Multidimensional Arrays

Preserve dimensions of multidimensional arrays in generated code.

Preserve Dimensions of Multidimensional Arrays in Generated Code

Preserve array dimensions for model data elements.

調整とテストのためのアクセス

Create Tunable Calibration Parameter in the Generated Code

In the generated code, create tunable parameter data that you can access during rapid prototyping and calibration.

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.

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.

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.

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.

Configure Packaging of Parameter Arguments in Generated Code

Customize the implementation of parameter arguments in generated 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.

名前付きデータ型とカスタム データ型

Control Data Type Names in Generated Code

Control the names of primitive, structure, and enumerated data types in the generated code.

Organize Data into Structures in Generated Code

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

Use Enumerated Data in Generated Code

Enumerated data is data that is restricted to a finite set of values. Create enumerations in the generated code.

Control File Placement of Custom Data Types

Integrate the generated code with your own code by placing typedef statements in generated and imported files.

Specify Boolean and Data Type Limit Identifiers

Integrate the generated code with your code by specifying the identifiers that correspond to Boolean false and true. Also, specify the identifiers that correspond to data type limits, which the generated code uses to determine overflows.

注目の例