Main Content

addrule

Add rule object to model

Description

ruleObj = addrule(modelObj,ruleExpression) creates a rule object ruleObj and adds the object to the SimBiology® model object modelObj. The function also assigns

  • ruleExpression to the Rule property of ruleObj.

  • modelObj to the Parent property of ruleObj.

  • 'initialAssignment' to the RuleType property for all assignment rules and 'algebraic' for all other rules.

To apply the rule in your simulation, set the Active property of ruleObj to true.

example

ruleObj = addrule(modelObj,ruleExpression,ruleType) also specifies the type of rule to create and add to the model. For more information on the types of rules, see Definitions and Evaluations of Rules in SimBiology Models.

example

ruleObj = addrule(___,Name=Value) also sets the properties of the rule object using one or more name-value arguments. Name is the property name and Value is the corresponding value.

Examples

collapse all

Create a SimBiology model.

m1 = sbiomodel("m1");
r1 = addreaction(m1,"A -> B")
r1 = 
   SimBiology Reaction Array

   Index:    Reaction:
   1         A -> B   

Create a rule that sets the initial values of species.

rule1 = addrule(m1,"A = 0.1")
rule1 = 
   SimBiology Rule Array

   Index:    RuleType:            Rule:  
   1         initialAssignment    A = 0.1

rule2 = addrule(m1,"B = 0.2")
rule2 = 
   SimBiology Rule Array

   Index:    RuleType:            Rule:  
   1         initialAssignment    B = 0.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.

rule3 = addrule(m1,'c = k*(a+b)')
rule3 = 
   SimBiology Rule Array

   Index:    RuleType:            Rule:      
   1         initialAssignment    c = k*(a+b)

Change the RuleType from default (initialAssignment') to 'rate'.

rule3.RuleType = "rate"
rule3 = 
   SimBiology Rule Array

   Index:    RuleType:    Rule:      
   1         rate         c = k*(a+b)

Use the get command to see the object properties.

get(rule3)
ans = struct with fields:
        Rule: 'c = k*(a+b)'
    RuleType: 'rate'
      Active: 1
        Name: 'Rule_3'
      Parent: [1x1 SimBiology.Model]
       Notes: ''
         Tag: ''
        Type: 'rule'
    UserData: []

Input Arguments

collapse all

SimBiology model, specified as a Model object.

Rule expression, specified as a character vector or string scalar.

Data Types: char | string

Type of the rule to be added, specified as "initialAssignment", "repeatedAssignment", "rate", or "algebraic". By default, the function uses "initialAssignment" for all assignment rules and "algebraic" for all other rules.

For more information on the types of rules, see Definitions and Evaluations of Rules in SimBiology Models.

Data Types: char | string

Output Arguments

collapse all

Added rule, returned as a Rule object.

Version History

Introduced in R2006a

expand all