Main Content


编写 Simscape™ 文件以表示自定义组件

使用 Simscape 语言,您可以将自定义组件定义为文本文件,并辅以参数化、物理连接和底层方程。本页中包含的主题提供有关声明组件参数、变量和连接的详细信息。有关定义自定义组件的其他方面,请参阅方程离散事件图和模式图复合组件

要开始编写自定义组件,请参阅Creating Custom Components,其中概述了常规工作流。本页底部“参考应用程序组件”下列出的主题提供了完整的组件示例,并详细解释了每个示例中使用的方法。


annotationsControl appearance of Simscape block based on the component
branchesEstablish relationship between component Through variables and nodes
componentComponent model keywords
inputsDefine component inputs, that is, Physical Signal input ports of block
nodesDefine component nodes, that is, conserving ports of block
outputsDefine component outputs, that is, Physical Signal output ports of block
parametersDeclare domain or component parameters
variablesDeclare domain or component variables




  • Declaring Domains and Components
    Declaration section of domain and component files: purpose, definitions, rules, member summaries.
  • Declare a Spring Component
    The following diagram shows a network representation of a mass-spring-damper system, consisting of four components (mass, spring, damper, and reference) in a mechanical rotational domain.
  • Declare Component Parameters
    Component parameters let you specify adjustable parameters for the Simscape block generated from the component file.
  • Declare Component Nodes
    Component nodes define the conserving ports of a Simscape block generated from the component file.
  • Declare Component Inputs and Outputs
    In addition to conserving ports, Simscape blocks can contain Physical Signal input and output ports, directional ports that carry signals with associated units.
  • Declare Component Variables
    When you declare Through and Across variables in a component, you are essentially creating instances of domain Through and Across variables.
  • Define Relationship Between Component Variables and Nodes
    How to connect Through and Across variables declared in a component file to the domain Through and Across variables.
  • Declaration Functions
    Use MATLAB® functions to compute derived parameter values or initialize variables.



  • Enumerations
    Specify a discrete set of acceptable values for parameters and event variables.
  • Subclassing and Inheritance
    Subclassing allows you to build component models based on other component models by extension.