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. These ports are defined in the
inputs
and outputs
declaration blocks of a component
file. Each input or output can be defined as:
A value with unit, where
value
can be a scalar, vector, or matrix. For a vector or a matrix, all signals have the same unit.An untyped identifier, to facilitate unit propagation.
Specifying an optional comment lets you control the port label and location in the block icon. For more information, see Customize the Names and Locations of the Block Ports.
This example declares an input port s
, with a default value of 1
Pa
, specifying the control port of a hydraulic pressure source. In the block
diagram, this port will be named Pressure and will be located on the top
side of the block icon.
inputs s = { 1, 'Pa' }; % Pressure:top end
The next example declares an output port v
as
a 3-by-3 matrix of linear velocities.
outputs v = {zeros(3), 'm/s'}; end
You can also reference component parameters in input and output declarations. For example, you can control the signal size by using a block parameter:
component MyTransformer parameters N = 3; % Number of windings end inputs I = {zeros(N, 1), 'A'}; end .... end
The following example declares an input port I
and output port
O
as untyped identifiers. In the block diagram, the output port will be
located on the right side of the block icon. The block propagates the unit and size of the
physical signal. For more information, see Physical Signal Unit Propagation.
inputs I; end outputs O; % :right end
Related Examples
- Declare a Spring Component
- Declare Component Variables
- Declare Component Parameters
- Declare Component Nodes