addcompartment (model, compartment)

Create compartment object


compartmentObj = addcompartment(modelObj, 'NameValue')
compartmentObj = addcompartment(owningCompObj, 'NameValue')
compartmentObj = addcompartment(modelObj, 'NameValue', CapacityValue)

compartmentObj = addcompartment(...'PropertyName', PropertyValue...)


modelObjModel object.
owningCompObjCompartment object that contains the newly created compartment object.
NameValueName for a compartment object. Enter a character string unique to the model object.

For information on naming compartments, see Name.

CapacityValueCapacity value for the compartment object. Enter double. Positive real number, default = 1.
PropertyNameEnter the name of a valid property. Valid property names are listed in Property Summary.
PropertyValueEnter the value for the property specified in PropertyName. Valid property values are listed on each property reference page.


compartmentObj = addcompartment(modelObj, 'NameValue') creates a compartment object and returns the compartment object (compartmentObj). In the compartment object, this method assigns a value (NameValue) to the property Name, and assigns the model object (modelObj) to the property Parent. In the model object, this method assigns the compartment object to the property Compartments.

compartmentObj = addcompartment(owningCompObj, 'NameValue') in addition to the above, adds the newly created compartment within a compartment object (owningCompObj), and assigns this compartment object (owningCompObj) to the Owner property of the newly created compartment object (compartmentObj). The parent model is the model that contains the owning compartment (owningCompObj).

compartmentObj = addcompartment(modelObj, 'NameValue', CapacityValue), in addition to the above, this method assigns capacity (CapacityValue) for the compartment.

If you define a reaction within a model object (modelObj) that does not contain any compartments, the process of adding a reaction generates a default compartment object and assigns the reaction species to the compartment. If there is more than one compartment, you must specify which compartment the species should be assigned to using the format CompartmentName.SpeciesName.

View properties for a compartment object with the get command, and modify properties for a compartment object with the set command. You can view a summary table of compartment objects in a model (modelObj) with get(modelObj, 'Compartments') or the properties of the first compartment with get(modelObj.Compartments(1)).

compartmentObj = addcompartment(...'PropertyName', PropertyValue...)
defines optional properties. The property name/property value pairs can be in any format supported by the function set (for example, name-value string pairs, structures, and name-value cell array pairs). Property Summary lists the properties. The Owner property is one exception; you cannot set the Owner property in the addcompartment syntax because, addcompartment requires the owning model or compartment to be specified as the first argument and uses this information to set the Owner property. After adding a compartment, you can change the owner using the function set.

Method Summary

Methods for compartment objects

addcompartment (model, compartment)Create compartment object
addspecies (model, compartment)Create species object and add to compartment object within model object
copyobj (any object)Copy SimBiology object and its children
delete (any object)Delete SimBiology object
display (any object)Display summary of SimBiology object
get (any object)Get object properties
rename (compartment, parameter, species, reaction)Rename object and update expressions
reorder (model, compartment, kinetic law)Reorder component lists
set (any object)Set object properties

Property Summary

Properties for compartment objects

CapacityCompartment capacity
CapacityUnitsCompartment capacity units
CompartmentsArray of compartments in model or compartment
ConstantCapacity Specify variable or constant compartment capacity
NameSpecify name of object
NotesHTML text describing SimBiology object
OwnerOwning compartment
ParentIndicate parent object
SpeciesArray of species in compartment object
TagSpecify label for SimBiology object
TypeDisplay SimBiology object type
UserDataSpecify data to associate with object


  1. Create a model object (modelObj).

    modelObj = sbiomodel('cell');
  2. Add two compartments to the model object.

    compartmentObj1 = addcompartment(modelObj, 'nucleus');
    compartmentObj2 = addcompartment(modelObj, 'mitochondrion');
  3. Add a compartment to one of the compartment objects.

    compartmentObj3 = addcompartment(compartmentObj2, 'matrix');
  4. Display the Compartments property in the model object.

    get(modelObj, 'Compartments')
    SimBiology Compartment Array
       Index:    Name:            Capacity:    CapacityUnits:
       1         nucleus          1            
       2         mitochondrion    1            
       3         matrix           1  
  5. Display the Compartments property in the compartment object.

    get(compartmentObj2, 'Compartments')
    SimBiology Compartment - matrix 
       Compartment Components:
         Capacity:          1
         Compartments:      0
         ConstantCapacity:  true
         Owner:             mitochondrion
         Species:           0
Was this topic helpful?