Main Content

Declare Component Parameters

Component parameters let you specify adjustable parameters for the Simscape™ block generated from the component file. Parameters will appear in the block dialog box and can be modified when building and simulating a model.

You declare each parameter as a value with unit. Specifying an optional comment lets you control the parameter name in the block dialog box. For more information, see Specify Meaningful Names for the Block Parameters and Variables.

The following example declares parameter k, with a default value of 10 N*m/rad, specifying the spring rate of a rotational spring. In the block dialog box, this parameter will be named Spring rate.

parameters
    k = { 10, 'N*m/rad' };   % Spring rate
end

Parameter Units

When you declare a component parameter, use the units that make sense in the context of the block application. For example, if you model a solenoid, it is more convenient for the block user to input stroke in millimeters rather than in meters. When a parameter is used in equations and other sections of a component file, Simscape unit manager handles the conversions.

With temperature units, however, there is an additional issue of whether to apply linear or affine conversion (see Thermal Unit Conversions). Therefore, when you declare a parameter with temperature units, you can specify only nonaffine units (kelvin or rankine). When the block user enters the parameter value in affine units (Celsius or Fahrenheit), this value is automatically converted to the units specified in the parameter declaration. By default, affine conversion is applied. If a parameter specifies relative, rather than absolute, temperature (in other words, a change in temperature), set its Conversion attribute to relative (for details, see Member Attributes).

Note

Member attributes apply to a whole declaration block. If some of your parameters are relative and others are absolute, declare them in separate blocks. You can have more than one declaration block of the same member type within a Simscape file.

Case Sensitivity

Simscape language is case-sensitive. This means that member names may differ only by case. However, Simulink® software is not case-sensitive. Simulink parameter names (that is, parameter names in a block dialog box) must be unique irrespective of case. Therefore, if you declare two parameters whose names differ only by case, such as

component MyComponent 
  parameters 
    A = 0; 
    a = 0; 
  end 
end 

you will not be able to generate a block from this component.

However, if one of the parameters is private or hidden, that is, does not appear in the block dialog box,

component MyComponent 
  parameters(Access=private) 
    A = 0; 
  end 
  parameters 
    a = 0; 
  end 
end 

then there is no conflict in the Simulink namespace and no problem generating the block from the component source.

Public component variables also appear in the block dialog box, on the Variables tab, because they are used for model initialization. These variables therefore compete with each other and with the block parameter names in the Simulink namespace. If a component has a public variable and a parameter whose names differ only by case, such as

component MyComponent 
  variables 
    A = 0; 
  end 
  parameters 
    a = 0; 
  end 
end 

you will not be able to generate a block from this component. As a possible workaround, you can declare the variable as private or hidden. In this case, the variable does not appear on the Variables tab of the resulting block dialog, and therefore there is no namespace conflict. However, if you want to be able to use the variable in the model initialization process, keep it public and change its name, or the name of the parameter.

The case-sensitivity restriction applies only to component parameters and public component variables, because other member types do not have an associated Simulink entity, and are therefore completely case-sensitive.

Related Examples

More About