Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

Push Button

使用按钮更改参数或变量值

  • Push Button block

库:
Simulink / Dashboard

描述

在仿真之前或仿真期间,使用 Push Button 模块更改所连接的变量或参数的值。您可以将按钮配置为仅在按下按钮时更改值,或在再次点击按钮前锁存值变化。将 Push Button 模块与其他 Dashboard 模块结合使用,可以创建交互式控制板来控制您的模型。

在仿真期间或 Push Button 模块处于选中状态时,双击该模块不会打开其对话框。要编辑模块参数,您可以使用属性检查器或通过以下方式打开模块对话框:

  • 当未选择模块且模型未仿真时,双击模块。

  • 右键点击模块并从上下文菜单中选择模块参数

普通按钮图标

您可以向 Push Button 模块添加图标,它会显示在普通按钮文本旁边。您可以从包括基本形状、汽车指示灯和无线图标的预定义集中选择一个图标,也可以上传自己的自定义图标。有关详细信息,包括内置图标的完整列表,请参阅图标

当您向 Push Button 模块添加图标时,您可以为图标配置一种打开颜色和一种关闭颜色,以便其颜色随着模块的状态而变化,并指定图标相对于普通按钮文本的对齐方式。例如,下图中的 Push Button 模块配置为使用圆形图标,且将表示打开状态的颜色指定为亮绿色,图标与按钮文本的左侧对齐。

Push button block with a green circle icon to the left of the button text.

您可以使用 Push Button 模块的图标设置在模型中配置模块的外观。如果您要进一步自定义模块的外观,请考虑使用 Customizable Blocks 库中的 Push Button 模块。Customizable Blocks 库中的 Push Button 模块支持添加自定义图标,但不包含任何内置图标。

连接 Dashboard 模块

Dashboard 模块不使用端口来连接到模型元素。要将 Dashboard 模块连接到变量和模块参数,请使用连接模式。连接模式有助于在模型中连接 Dashboard 模块,尤其是需要一次连接多个模块时。要连接单个 Dashboard 模块,还可以使用模块对话框中的连接表。

提示

您可以在普通和加速模式下的仿真期间修改模型中的 Dashboard 模块连接。

注意

在更新模型图之前,Dashboard 模块无法连接到变量。当打开模型后,若要在运行仿真前将 Dashboard 模块连接到变量或修改变量值,请使用 Ctrl+D 更新模型图。

要进入连接模式,请在画布中选择要连接的 Dashboard 模块。在 Simulink® 工具条上,会出现以所选模块的类型命名的选项卡。在模块选项卡上,点击连接。在连接模式下,当您选择一个或多个模块时,会出现可用于连接的参数和变量的列表。从列表中选择变量或参数,以连接到所选 Dashboard 模块。

当所选变量或模块参数的值是非标量时,请使用连接表底部的文本框来指定要连接到 Dashboard 模块的元素。要连接到向量、矩阵或数组的元素,请指定元素索引,例如 3(1,3)。要连接到总线或结构体中的元素,请在总线或结构体层次结构的上下文中指定元素,方法是使用点来指示层次结构中的不同级别并省略顶层。例如,指定 a.b 以连接到嵌套在所选复合变量或参数内的结构体或总线 a 的标量元素 b

要连接另一个 Dashboard 模块,请在这另一个模块上悬停并点击其上方的连接按钮。然后,在模型中选择信号和模块,并选择要连接的模型元素。

A Knob block from the Dashboard library is in connect mode. To the right of the Knob block is a Sine Wave block that connects to a Gain block that connects to an Outport block. To the right of the Outport block is the list of parameters and variables available for connection.

完成模型中 Dashboard 模块的连接后,在模块选项卡上,点击完成连接

提示

您可以使用具有 ShowInitialText 模块参数的 set_param 函数隐藏在未连接的模块上显示的消息。当您连接模块时,消息也会消失。

参数记录

连接到 Dashboard 模块的可调参数数据会记录到仿真数据检查器,您可以在其中查看参数值以及记录的信号数据。您可以通过使用 UI 或 Simulink.sdi.exportRun 函数从仿真数据检查器导出参数数据来访问 MATLAB® 工作区中记录的参数数据。有关使用仿真数据检查器 UI 导出数据的详细信息,请参阅将数据导出到工作区或文件。参数数据存储在 Simulink.SimulationData.Parameter 对象中,可作为导出的 Simulink.SimulationData.Dataset 中的元素来访问。

限制

  • 除了 Dashboard Scope 模块和 Display 模块之外,Dashboard 模块只能连接到实数标量信号。

  • 工具条不支持面板内的模块。

  • 您不能在模块对话框中使用连接表将 Dashboard 模块连接到已注释掉的模块。使用连接模式将 Dashboard 模块连接到带注释的模块时,Dashboard 模块在您取消注释模块之前不会显示连接的值。

  • Dashboard 模块无法连接到引用模型中的模型元素。

  • 在仿真模型层次结构时,引用模型内的 Dashboard 模块不会更新。

  • Dashboard 模块不支持快速加速仿真。

  • 当您在仿真期间将 Dashboard 模块连接到变量或参数时,该变量或参数的数据不会记录到仿真数据检查器中。要将变量和参数数据记录到仿真数据检查器,请在仿真之前将 Dashboard 模块连接到该变量或参数。

  • 当您将默认参数行为设置为内联并在外部模式下对模型进行仿真时,Dashboard 模块看起来像是更改了参数和变量值。但是,更改不会传播到仿真。例如,Gain 模块显示使用 Dashboard 模块对增益参数进行的更改,但仿真中使用的增益值不变。

参数

全部展开

连接

选择要使用连接表进行控制的变量或模块参数。要将模块连接到信号,请执行下列步骤:

  1. 在包含一个或多个模块的模型中进行选择。

  2. 选择要连接的变量或参数。

    当所选变量或模块参数的值是非标量时,请使用连接表底部的文本框来指定要连接到 Dashboard 模块的元素。要连接到向量、矩阵或数组的元素,请指定元素索引,例如 3(1,3)。要连接到总线或结构体中的元素,请在总线或结构体层次结构的上下文中指定元素,方法是使用点来指示层次结构中的不同级别并省略顶层。例如,指定 a.b 以连接到嵌套在所选复合变量或参数内的结构体或总线 a 的标量元素 b

  3. 点击应用

为了便于理解和调试您的模型,您可以在仿真期间将 Dashboard 模块连接到模型中的变量和参数。

注意

要查看连接表中的工作区变量,请使用 Ctrl+D 更新模型图。

编程用法

要以编程方式将 Dashboard 模块连接到可调参数或变量,请使用 Simulink.HMI.ParamSourceInfo 对象。Simulink.HMI.ParamSourceInfo 对象包含四个属性。有些属性适用于将 Dashboard 模块连接到参数,有些属性适用于将 Dashboard 模块连接到变量。并非所有字段都有与连接对应的值,因为一个给定的 Dashboard 模块只能连接到参数或变量之一。

模块参数Binding
类型:Simulink.HMI.ParamSourceInfo
默认值:[]

常设

模型中的 Push Button 模块上显示的文本。

提示

要设计根据模块的状态显示不同文本的普通按钮,请使用 Customizable Blocks 库中的 Push Button 模块。

编程用法

模块参数ButtonText
类型:字符串或字符数组
默认值'Button'

当按下或锁存按钮时赋给所连接的模块参数的值。

提示

使用模块类型参数配置模块如何响应点击:

  • 瞬时 - 按钮仅在按下时应用打开值

  • 锁存 - 在点击按钮时按钮会锁存状态变化,并在您再次点击之前一直应用打开值

编程用法

模块参数OnValue
类型:字符串或字符数组
默认值:'1'

指定按钮如何响应点击。

  • 瞬时 - 按钮仅在按下时应用打开值

  • 锁存 - 在点击按钮时按钮会锁存状态变化,并在您再次点击之前一直应用打开值

编程用法

模块参数ButtonType
类型:字符串或字符数组
'Momentary' | 'Latch'

模块标签的位置。当模块连接到模型中的元素时,标签是所连接的元素的名称。

编程用法

模块参数LabelPosition
类型:字符向量
值:'Hide' | 'Bottom' | 'Top'
默认值'Hide'

格式

模块背景不透明度,指定为 0 到 1 之间的标量值。

示例: 0.5

编程用法

模块参数:Opacity
类型:标量
默认值: 1

模块前景颜色,包括文本。您可以从标准颜色调色板中选择一种颜色,也可以指定自定义颜色。

编程用法

将模块的 ForegroundColor 参数指定为字符串或字符向量,该向量定义 1×3 [r g b] 向量,其值介于 01 之间。

模块参数ForegroundColor
类型:字符向量 | 字符串
值:[r g b] 向量

模块的背景色。您可以从标准颜色调色板中选择一种颜色,也可以指定自定义颜色。

编程用法

将模块的 BackgroundColor 参数指定为字符串或字符向量,该向量定义 1×3 [r g b] 向量,其值介于 01 之间。

模块参数BackgroundColor
类型:字符向量 | 字符串
值:[r g b] 向量

图标

您可以向 Push Button 模块添加显示在按钮文本旁边或代替按钮文本的图标。您可以从内置形状、汽车图标和无线图标中进行选择,也可以上传您自己的自定义 SVG、PNG 或 JPEG 文件用作图标。

要查看图标选项,请在模块对话框的图标选项卡上选择图标类型。要使用您自己的自定义图标,请选择自定义作为图标类型,并上传图像文件。

添加图标时,可以使用以下参数配置图标外观:

  • 图标对齐方式 - 图标相对于按钮文本的对齐方式

  • 打开颜色 - 按下或锁存模块并将打开值应用于所连接的参数时的图标颜色

  • 关闭颜色 - 当未按下或锁存模块且未将打开值应用于所连接的参数时的图标颜色

要为图标指定打开颜色关闭颜色,您必须选择自定义图标颜色

形状图标

图标基本形状库模块名称编程使用的值

Check1 icon: a check mark

Check1Check1

Check2 icon: a check mark with slightly curved lines

Check2Check2

Check3 icon: the outline of a check mark

Check3Check3

Check4 icon: a check mark with a divot along its outline

Check4Check4

Circle icon: a solid black circle

CircleCircle

Ex1 icon: a cross mark

Ex1Ex1

Ex2 icon: a cross mark with one curved line

Ex2Ex2

Ex3 icon: the outline of a cross mark

Ex3Ex3

Ex4 icon: a cross mark with a divot along the outline

Ex4Ex4

Face icon: the outline of a face with a closed mouth in a straight line

FaceFace

Frown1 icon: the outline of a face with an open downturned mouth

Frown1Frown1

Frown2 icon: the outline of a face with a closed downturned mouth

Frown2Frown2

Hexagon icon: a solid hexagon

HexagonHexagon

Pentagon icon: a solid pentagon

PentagonPentagon

Rectangle icon: a solid rectangle

RectangleRectangle

Smile1 icon: the outline of a face with an open upturned mouth

Smile1Smile1

Smile2 icon: the outline of a face with a closed upturned mouth

Smile2Smile2

Solid Face icon: a solid face with a closed mouth in a straight line

Solid FaceSolidFace

Solid Frown1 icon: a solid face with an open downturned mouth

Solid Frown1SolidFrown1

Solid Frown2 icon: a closed downturned mouth

Solid Frown2SolidFrown2

Solid Smile1 icon: a solid face with an open upturned mouth

Solid Smile1SolidSmile1

Solid Smile2 icon: a solid face with a closed upturned mouth

Solid Smile2SolidSmile2

Square icon: a solid square

SquareSquare

Triangle icon: a solid triangle

TriangleTriangle

汽车图标

图标汽车指示灯库模块名称编程使用的值

Adaptive Cruise Control icon: a speedometer with an arrow pointing to a tickmark and the silhouette of a car in the background

Adaptive Cruise ControlAdaptiveCruiseControl

Adaptive Cruise Control Failure icon: a speedometer with an exclamation mark next to it and the silhouette of a car in the background

Adaptive Cruise Control FailureAdaptiveCruiseControlFailure

Antilock Brake System icon: a circle labeled "ABS" in a set of parentheses

Antilock Brake SystemAntilockBrakeSystem

Battery icon: the outline of a battery with a plus symbol on the positive pole, and a negative symbol on the negative pole

BatteryBattery

Check Engine icon: the outline of an engine labeled "Check Engine"

Check EngineCheckEngine

Check Engine2 icon: the outline of an engine with the silhouette of a lightning rod on it and the word "CHECK" underneath it

Check Engine2CheckEngine2

Cruise Control icon: a speedometer with an arrow pointing to one of the tickmarks

Cruise ControlCruiseControl

Eco Mode icon: a solid leaf shape labeled "ECO"

Eco ModeEcoMode

Electronic Stability icon: a circle labeled "ESP" in a set of parentheses

Electronic StabilityElectronicStability

Engine icon: the silhouette of an engine

EngineEngine

Engine Coolant Temp icon: a thermometer with waves in the background

Engine Coolant TempEngineCoolantTemp

Engine Failure icon: the silhouette of an engine with an exclamation mark on it

Engine FailureEngineFailure

Engine Heating icon: the silhouette of an engine with three wavy arrows pointing upwards on it

Engine HeatingEngineHeating

Engine Oil icon: the silhouette of an oil can

Engine OilEngineOil

Exterior Bulb Failure icon: the silhouette of a glowing light bulb with an exclamation mark on it

Exterior Bulb FailureExteriorBulbFailure

Front Fog Light icon: the outline of a fog light lamp emitting rays of light to the left that are depicted as diagonal lines on top of a wavy vertical line that represents the fog

Front Fog LightFrontFogLight

Fuel icon: the silhouette of a gas pump with an arrow pointing left on it

FuelFuel

Hazards icon: the outline of a warning triangle

HazardsHazards

Headlamp Leveling icon: the outline of a lamp emitting rays of light with an arrow pointing clockwise above them and an arrow pointing counterclockwise below them

Headlamp LevelingHeadlampLeveling

High Beams icon: the outline of a lamp emitting horizontal rays of light

High BeamsHighBeams

Hill Descent Control icon: the outline of a car driving down a slope

Hill Descent ControlHillDescentControl

Lighting Switch icon: the silhouette of a glowing light bulb

Lighting SwitchLightingSwitch

High Beams icon: the outline of a lamp emitting rays of light that run diagonally downward

Low BeamsLowBeams

Parking Assistance icon: the letter "P" next to a solid triangle, and the "P" emits a detection signal represented as three curved lines aimed at the triangle

Parking AssistanceParkingAssistance

Rear Fog Light icon: the outline of a fog light lamp emitting rays of light to the right that are depicted as horizontal lines on top of a wavy vertical line that represents the fog

Rear Fog LightRearFogLight

Side Lights icon: the outline two lamps emitting rays of light to the left and right

Side LightsSideLights

Stability Control icon: the silhouette of a car with wavy lines behind it

Stability ControlStabilityControl

Stability Control Off icon: the silhouette of a car with wavy lines behind it and the word "OFF" underneath

Stability Control OffStabilityControlOff

Tire Monitor icon: the outline of the cross-section of a tire with an exclamation mark on it

Tire MonitorTireMonitor

Traction Control icon: the outline of the cross-section of a tire with the label "TC"

Traction ControlTractionControl

Traction Control Off icon: the outline of the cross-section of a tire with the label "TC" and a diagonal slash through the whole image

Traction Control OffTractionControlOff

Traction Control Failure icon: the outline of the cross-section of a tire with the label "TC" and an exclamation mark next to it

Traction Control FailureTractionControlFailure

Turn Signal Left icon: a solid arrow pointing left

Turn Signal LeftTurnSignalLeft

Turn Signal Right icon: a solid arrow pointing right

Turn Signal RightTurnSignalRight

无线图标

图标图标名称编程使用的值

Network icon: the wireless internet connection icon

NetworkNetwork

Network No Signal icon: the wireless internet connection icon grayed out,with a crossed-out circle next to it

Network No SignalNetworkNoSignal

Network Transmission icon: a wireless internet tower

Network TransmissionNetworkTransmission

Network3G icon: the wireless internet connection icon with "3G" next to it

Network3GNetwork3G

Network4G icon: the wireless internet connection icon with "4G" next to it

Network4GNetwork4G

Network5G icon: the wireless internet connection icon with "4G" next to it

Network5GNetwork5G

提示

  • 您可以使用工具条中的按钮选项卡更改 Push Button 模块的图标。

  • 如果您要进一步自定义 Push Button 模块的外观,请考虑使用 Customizable Blocks 库中的 Push Button 模块设计您自己的按钮。

    Customizable Blocks 库中的 Push Button 模块支持添加自定义图标,但不包含任何内置图标。

  • 图标的打开颜色和关闭颜色可以应用于以下 SVG 元素:

    • altGlyph

    • circle

    • ellipse

    • path

    • polygon

    • rect

    • text

    • textPath

    • tref

    • tspan

编程用法

模块参数Icon
类型:字符串 | 字符向量
默认值:'Default'

图标相对于按钮文本的对齐方式。如果不指定按钮文本,图标将始终位于模块的中心。

编程用法

模块参数IconAlignment
类型:字符串 | 字符向量
'Left' | 'Right' | 'Top' | 'Bottom' | 'Center'
默认值'Left'

当您向 Push Button 模块添加图标时,您可以指定打开颜色和关闭颜色,以使图标颜色发生变化来反映模块的状态。要使用并指定图标的打开颜色关闭颜色,请选择自定义图标颜色

编程用法

模块参数IconColor
类型:字符串 | 字符向量
'On' | 'Off'
默认值'Off'

当您向 Push Button 模块添加图标时,您可以指定打开颜色和关闭颜色,以使图标颜色发生变化来反映模块的状态。打开颜色指定按下或锁存模块并将打开值应用于所连接的参数时图标的颜色。您可以从标准颜色调色板中选择一种颜色,也可以指定自定义颜色。

依存关系

要启用打开颜色参数,请选择自定义图标颜色

编程用法

将模块的 IconOnColor 参数指定为 1×3 [r g b] 向量,其值介于 01 之间。

模块参数IconOnColor
类型:[r g b] 向量

当您向 Push Button 模块添加图标时,您可以指定打开颜色和关闭颜色,以使图标颜色发生变化来反映模块的状态。关闭颜色指定未按下或锁存模块且未将打开值应用于所连接的参数时图标的颜色。您可以从标准颜色调色板中选择一种颜色,也可以指定自定义颜色。

依存关系

要启用打开颜色参数,请选择自定义图标颜色

编程用法

将模块的 IconOffColor 参数指定为 1×3 [r g b] 向量,其值介于 01 之间。

模块参数IconOffColor
类型:[r g b] 向量

模块特性

数据类型

double | half | integer | single

直接馈通

多维信号

可变大小信号

过零检测

扩展功能

版本历史记录

在 R2015a 中推出

全部展开