Define domain or component variables
variables comp_var1 = {value ,'unit'}; end
variables comp_var2 = {value = {value,'unit'}, priority = priority.value, nominal = {value,'unit'} }; end
variables domain_across_var1 = {value,'unit'}; end
variables(Balancing = true) domain_through_var1 = {value,'unit'}; end
variables
begins a variables declaration
block, which is terminated by an end
keyword. In a component file,
this block contains declarations for all the variables associated with the component. In
a domain file, this block contains declarations for all the Across variables associated
with the domain. Additionally, domain files must have a separate variables declaration
block, with the Balancing
attribute set to true
,
which contains declarations for all the Through variables associated with the domain.
In a component file, the following syntax defines an Across,
Through, or internal variable, comp_var1
, as a value with unit. value
is
the initial value. unit
is a valid unit string,
defined in the unit registry.
variables comp_var1 = { value , 'unit' }; end
For component variables, you can additionally specify the initialization priority, as well as nominal value and unit, by declaring the variable as a field array.
variables comp_var2 = { value = { value , 'unit' }, priority = priority.value, nominal = { value , 'unit' } }; end
The first field in the array is value
(value with unit). The other two fields are optional and can come in any
order.
The priority
field can be one of three values listed in the
following table:
Priority field in Simscape™ language | Resulting default priority in the block dialog box |
---|---|
priority = priority.high | High |
priority = priority.low | Low |
priority = priority.none (this is the default) | None |
Note
It is recommended that you use the priority
attribute
sparingly. The default priority value, priority.none
(which is
equivalent to leaving out the priority
attribute entirely), is
suitable in most cases. The block user can modify the variable priority value, as
needed, in the Variables tab of the block dialog box prior to
simulation.
The nominal
field must be a value with unit, where value
is the nominal value, that
is, the expected magnitude of the variable. unit
is a valid unit
string, defined in the unit registry.
Note
It is recommended that you use the nominal
attribute sparingly.
The default nominal values, which come from the model value-unit table, are suitable
in most cases. The block user can also modify the nominal values and units for
individual blocks by using either the Property Inspector or
set_param
and get_param
functions, if
needed. For more information, see Modify Nominal Values for a Block Variable.
You can also specify the variable name, the way you want it to appear in the Variables tab of the block dialog box, as a comment:
variables comp_var1 = { value , 'unit' }; % Variable name end
In a domain file, the following syntax defines an Across variable, domain_across1
,
as a value with unit. value
is
the initial value. unit
is a valid unit string,
defined in the unit registry.
variables domain_across_var1 = { value , 'unit' }; end
In a domain file, the following syntax defines a Through variable, domain_through1
,
as a value with unit. value
is
the initial value. unit
is a valid unit string,
defined in the unit registry.
variables(Balancing = true) domain_through_var1 = { value , 'unit' }; end
This example initializes the variable w
(angular
velocity) as 0 rad/s:
variables w = { 0, 'rad/s' }; % Angular velocity end
This example initializes the variable x
(spring
deformation) as 0 mm, with high priority:
variables x = { value = { 0 , 'mm' }, priority = priority.high }; % Spring deformation end
This example initializes the domain Through variable t
(torque)
as 1 N*m:
variables(Balancing = true) t = { 1, 'N*m' }; end