Documentation Center

  • Trial Software
  • Product Updates

variables

Define domain or component variables

Syntax

variables comp_var1 = { value , 'unit' }; end     
variables comp_var2 = { value = { value , 'unit' }, priority = priority.value }; end
variables domain_across_var1 = { value , 'unit' }; end
variables(Balancing = true) domain_through_var1 = { value , 'unit' }; end

Description

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

Additionally, you can specify the initialization priority for component variables by declaring a variable as a field array.

variables
    comp_var2 = { value = { value , 'unit' }, priority = priority.value };
end

The first field in the array is value (value with unit). The second field is priority, which can be one of three values listed in the following table:

Priority field in Simscape™ languageResulting default priority in the block dialog box
priority = priority.highHigh
priority = priority.lowLow
priority = priority.none (this is the default)Unused

    Note:   MathWorks recommends 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.

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

Examples

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
Was this topic helpful?