主要内容

控制数据类型的信号

控制Simulink中信号的数据类型金宝app®模型,您为相应的块输出指定数据类型。

您还可以以以下任何方式将特定数据类型的新信号引入模型:

  • Load signal data of the desired type from the MATLAB®通过根级进入模型的工作区企业块或a从工作区堵塞。

  • 创建一个持续的阻止您的模型并将其参数设置为所需类型。

  • Use a数据类型转换块将信号转换为所需的数据类型。

Simulink blocks determine the data type of their outputs by default. Many blocks allow you to override the default type and explicitly specify an output data type, using a block parameter that is typically namedOutput data type。例如,Output data typeparameter appears on theSignal Attributes恒定块对话框的窗格。

看the following topics for more information:

有关... 看...

Valid data type values that you can specify

输入有效的数据类型值

An assistant that helps you specify valid data type values

使用数据类型助手指定数据类型

Specifying valid data type values for multiple blocks simultaneously

使用模型数据编辑器进行批处理编辑

输入有效的数据类型值

通常,您可以将输出数据类型指定为以下任何一个:

Valid data type values vary among blocks. You can use the pull-down menu associated with a block data type parameter to view the data types that a particular block supports. For example, the数据类型“数据存储存储器块”对话框上的下拉菜单列出了它支持的数据类型,如下所示。金宝app

有关特定块支持的数据类型的更多信息,请参见Simulink文档中的块文档。金宝app金宝app

数据类型继承规则

Blocks can inherit data types from a variety of sources, including signals to which they are connected and particular block parameters. You can specify the value of a data type parameter as a rule that determines how the output signal inherits its data type. To view the inheritance rules that a block supports, use the data type pull-down menu on the block dialog box. The following table lists typical rules that you can select.

继承规则 Description
继承:通过背部传播继承

Simulink automatically determines the output data type of the block during data type propagation (see数据类型传播)。在这种情况下,该块使用下游块或信号对象的数据类型。

Inherit: Same as input

该块将其唯一输入信号的数据类型用于其输出信号。

继承:与第一输入相同

该块将其第一个输入信号的数据类型用于其输出信号。

继承:与第二输入相同

该块将其第二输入信号的数据类型用于其输出信号。

继承:通过内部规则继承

该块使用内部规则来确定其输出数据类型。内部规则选择了一种数据类型,该数据类型可以优化数值准确性,性能和生成的代码大小,同时考虑到嵌入式目标硬件的属性。该软件并非总是可以同时优化效率和数值准确性。

When you apply inherited data types to a signal, Simulink determines the specific data type of the signal only after you update the block diagram.

  • 要在框图上显示此特定数据类型,请参见端口数据类型

  • To inspect this specific data type for multiple signals in a searchable, sortable table, use the Model Data Editor (on theModeling选项卡,单击Model Data Editor)。右侧数据类型列显示了每个信号的特定数据类型。有关更多信息,请参阅Model Data Editor

内置数据类型

您可以将数据类型参数的值指定为内置数据类型的名称,例如单身的或者布尔。To view the built-in data types that a block supports, use the data type pull-down menu on the block dialog box. SeeSimulink支持的金宝app数据类型金宝app对于所有支持的内置数据类型的列表。金宝app

数据类型表达式

您可以将数据类型参数的值指定为评估数字数据类型对象的表达式。只需在“块”对话框上的数据类型字段中输入表达式。通常,输入以下表达式之一:

  • FIXDTCommand

    将数据类型参数的值指定为调用的命令FIXDT功能。此功能使您可以创建一个金宝appsimulink.numerictypeobject that describes a fixed-point or floating-point data type.

  • 数据类型Object Name

    将数据类型参数的值指定为代表数据类型的数据对象的名称。金宝app您从类实例化的模拟数据对象,例如金宝appsimulink.numerictype金宝appsimulink.Airstype,简化对输出数据类型进行模型更改的任务,并允许您为数据类型使用自定义别名。看数据对象有关Simulink数据对象的更多信息。金宝app

使用模型数据编辑器进行批处理编辑

使用Model Data Editor相同数据类型,您可以分配到多个signals simultaneously. You can use this technique to design the interface of your model by configuring data types and other attributes of multiple企业外港一次块(请参阅配置数据接口)。You can also finely control the data types of arbitrary signals in your block algorithm.

例如,SlexaircraftExamplemodel in theAircraft Longitudinal Flight Control示例包含许多获得blocks. Suppose you want to specify the output data type of the three Gain blocks at the root level of the model as单身的。You can achieve this task as follows:

  1. In the Model Data Editor (on theModeling选项卡,单击Model Data Editor),,,,inspect theSignalstab.

  2. Next to the过滤内容盒子,切换Filter using selectionbutton.

  3. 在模型的最高级别,选择表示三个输出的信号线获得块(标记Zw,,,,MW, 和MQ)。模型数据编辑器显示了与三个信号相对应的三行。

  4. In the Model Data Editor, select all three signals (rows). For example, you can pressctrl+a或保持转移在单击顶部和底部行时资源柱子。

  5. 对于这三个信号中的任何一个,请单击该单元格数据类型柱子。从下拉列表中,选择单身的。模型数据编辑器applies this selection to all of the selected rows.

要将模型转换为严格的单个精确设计,请参见验证浮点嵌入式模型

Share a Data Type Between Separate Algorithms, Data Paths, Models, and Bus Elements

In some cases, you cannot rely on data type inheritance (see数据类型继承规则)to establish equivalence between the data types of different data items (such as signal lines in parallel data paths or bus elements in aSimulink.Bus目的)。相反,您可以创建一个金宝appsimulink.numerictype或者金宝appsimulink.Airstype工作区或数据字典中的对象。

创建一个金宝appsimulink.numerictype如果您不想通过创建别名来重命名共享数据类型,则对象。设置ISALIAS财产为false(the default).

This example shows how to use a金宝appsimulink.numerictype对象在同一模型中的两个查找表块之间共享输出数据类型。

  1. 打开Modeling a Fault-Tolerant Fuel Control System示例模型sldemo_fuelsys

    openexample('simulink_automotive/ModelingAFaultTolerantFuelControlSystemExample')sldemo_fuelsys

    模型创建金宝appsimulink.numerictypeobjects in the base workspace. One of the objects is namedS16en15

  2. 在命令提示下,检查S16en15

    S16en15
    S16en15= NumericType with properties: DataTypeMode: 'Single' IsAlias: 0 DataScope: 'Auto' HeaderFile: '' Description: ''

    该对象表示内置的simulink数据类型金宝app单身的

  3. 在模型中,导航到fuel_rate_control/airflow_calcsubsystem.

  4. Modeling选项卡,单击Model Data Editor。在模型数据编辑器中,检查Signalstab.

  5. 在模型中,单击Pumping Constant堵塞。模型数据编辑器数据类型列显示信号数据类型设置为S16en15

  6. 单击的输出信号坡道率ki堵塞。The output data type of this block is also set toS16en15

  7. Update the block diagram and, if necessary, expand the width of the数据类型柱子。列的右侧显示了两个查找表块使用数据类型单身的

  8. At the command prompt, configureS16en15to represent the data typedouble

    s16en15.datatypemode ='双倍的';

  9. Update the block diagram.

    现在使用数据类型的两个查找表块的输出信号double。Due to data type inheritance, other signals, such asE0E1,获取相同的数据类型。

另外,要在同一模型中建立算法或数据路径之间的数据类型等效性,您可以使用诸如数据类型传播数据类型转换继承。当您使用这些块时,您无需创建和永久存储数据类型对象。但是,除非模型在同一模型参考层次结构中,否则您不能使用块在不同模型中的信号之间共享数据类型。

重用信号数据的自定义C数据类型

在模型中,您可以创建符合自定义C数据类型(例如结构)定义的信号。使用这些信号:

  • 用Simulink模型替换现有的C代码。金宝app

  • Integrate C code for simulation in Simulink (for example, by using the Legacy Code Tool).

  • 准备生成代码(金宝appSimulink Coder™)that you can integrate with existing code.

Use these techniques to match your custom data types:

要创建这些类和对象,您可以使用该功能金宝appsimulink.importexternalctypes

如果一个MATLAB Function块或状态流®模型中的图表使用导入的枚举或结构类型,配置模型配置参数以包含(#包括)来自外部标头文件的类型定义。看Control Imported Bus and Enumeration Type Definitions(为一个MATLAB Function块)和Access Custom Code Variables and Functions in Stateflow Charts(状态流)将自定义结构集成到状态流图中(状态流)(为一个chart).

确定使用继承设置的信号的数据类型

当信号使用继承的数据类型设置时继承:通过内部规则继承(大多数块的默认设置),确定信号用于仿真的有意义的数据类型,更新框图,然后使用以下一项或两种技术:

  • 在Simuli金宝appnk编辑中,在调试tab, select信息叠加并导航到端口部分。选择要显示的端口数据类型。数据类型出现在每个信号旁边的框图上。有关更多信息,请参阅端口数据类型

  • Inspect the right side of the数据类型模型数据编辑器中的列(在Modeling选项卡,单击Model Data Editor)。有关更多信息,请参阅Model Data Editor

使用se techniques to inspect data types helps you to:

  • 在高级别上设计模型的数据类型策略。

  • 由于量化和溢出而引起的调试数值问题。

  • 在共享时使模型更容易理解。

有关更多信息,请参阅端口数据类型

数据类型仍然存在double尽管设置更改

If many of the data items (signals, parameters, and states) in your model continue to use the data typedoubleafter you configure block parameters such asOutput data type,,,,confirm that the model is not configured to override data types. See控制数据类型覆盖

也可以看看

||

相关话题