Main Content

addrule (model)

Create rule object and add to model object


ruleObj = addrule(modelObj, Rule)
ruleObj = addrule(modelObj, Rule, RuleType)
ruleObj = addrule(..., 'PropertyName', PropertyValue,...)


modelObjModel object to which to add the rule.
Rule Character vector specifying the rule. For example, enter the algebraic rule 'Va*Ea + Vi*Ei - K2'.

Character vector specifying the type of rule. Choices are:

  • 'algebraic'

  • 'initialAssignment'

  • 'repeatedAssignment'

  • 'rate'

For more information, see RuleType


A rule is a mathematical expression that changes the amount of a species or the value of a parameter. It also defines how species and parameters interact with one another.

ruleObj = addrule(modelObj, Rule) constructs and returns ruleObj, a rule object. In ruleObj, the rule object, this method assigns the modelObj input argument to the Parent property, assigns the Rule input argument to the Rule property, and assigns 'initialAssignment' or 'algebraic' to the RuleType property. (This method assigns 'initialAssignment' for all assignment rules and 'algebraic' for all other rules.) In modelObj, the model object, this method assigns ruleObj, the rule object, to the Rules property.

ruleObj = addrule(modelObj, Rule, RuleType) in addition to the assignments above, assigns the RuleType input argument to the RuleType property. For more information on the types of rules, see RuleType.

ruleObj = addrule(..., 'PropertyName', PropertyValue,...) defines optional properties. The property name/property value pairs can be in any format supported by the function set.

View additional rule properties with the function get, and modify rule properties with the function set. Copy a rule object to a model with the function copyobj, or delete a rule object from a model with the function delete.


If you use the addrule method to create an algebraic rule, rate rule, or repeated assignment rule, and the rule expression is not continuous and differentiable, see Using Events to Address Discontinuities in Rule and Reaction Rate Expressions before simulating your model.

Method Summary

Methods for rule objects

copyobjCopy SimBiology object and its children
deleteDelete SimBiology object
displayDisplay summary of SimBiology object
getGet SimBiology object properties
renameRename SimBiology model component and update expressions
setSet SimBiology object properties

Property Summary

Properties for rule objects

ActiveIndicate object in use during simulation
NameSpecify name of object
NotesHTML text describing SimBiology object
ParentIndicate parent object
RuleSpecify species and parameter interactions
RuleTypeSpecify type of rule for rule object
TagSpecify label for SimBiology object
TypeDisplay SimBiology object type
UserDataSpecify data to associate with object


Add a rule with the default RuleType.

  1. Create a model object, and then add a rule object.

    modelObj = sbiomodel('cell');
    ruleObj = addrule(modelObj, '0.1*B-A')
  2. Get a list of properties for a rule object.

    get(modelObj.Rules(1)) or get(ruleObj)

    MATLAB displays a list of rule properties.

        Active: 1
        Annotation: ''
              Name: ''
             Notes: ''
            Parent: [1x1 SimBiology.Model]
              Rule: '0.1*B-A'
          RuleType: 'algebraic'
               Tag: ''
              Type: 'rule'
          UserData: []

Add a rule with the RuleType property set to rate.

  1. Create model object, and then add a reaction object.

    modelObj = sbiomodel ('my_model');
    reactionObj = addreaction (modelObj, 'a -> b');
  2. Add a rule which defines that the quantity of a species c. In the rule expression, k is the rate constant for a -> b.

    ruleObj = addrule(modelObj, 'c = k*(a+b)')
  3. Change the RuleType from default ('algebraic') to 'rate', and verify using the get command.

    set(ruleObj, 'RuleType', 'rate');

    MATLAB returns all the properties for the rule object.

        Active: 1
    Annotation: ''
          Name: ''
         Notes: ''
        Parent: [1x1 SimBiology.Model]
          Rule: 'c = k*(a+b)'
      RuleType: 'rate'
           Tag: ''
          Type: 'rule'
      UserData: []

Version History

Introduced in R2006a

expand all