Main Content


Create compartment object and add to model or compartment



compartmentObj = addcompartment(modelCompartmentObj,compName) creates and returns a Compartment object compartmentObj. The function also assigns

  • compName to the Name property of compartmentObj.

  • modelCompartmentObj to the Parent property of compartmentObj.

  • compartmentObj to the Compartments property of the model object or compartment object modelCompartmentObj.

  • A value of 1 to the Value property of compartmentObj.

compartmentObj = addcompartment(modelCompartmentObj,compName,capacityValue) also assigns the Value property of compartmentObj to capacityValue.


compartmentObj = addcompartment(___,Name=Value) also sets the properties of compartmentObj using one or more name-value arguments. Name is the property name and Value is the corresponding value. The Owner property is one exception; you cannot set the Owner property because the function requires the owning model or compartment to be specified as the first argument and uses this information to set the Owner property.


collapse all

This example shows how to add compartments to a SimBiology model.

Create a SimBiology model which is named m1.

model = sbiomodel('m1');

Add two compartments to the model, which are named as Central and Peripheral respectively.

comp1 = addcompartment(model,'Central');
comp2 = addcompartment(model,'Peripheral');

Change the compartment capacities and units.

comp1.Capacity = 2;
comp1.CapacityUnits = 'liter';
comp2.Capacity = 1;
comp2.CapacityUnits = 'liter';

Display all the compartments of the model.

ans = 
   SimBiology Compartment Array

   Index:    Name:         Value:    Units:
   1         Central       2         liter 
   2         Peripheral    1         liter 

Input Arguments

collapse all

SimBiology model or compartment, specified as a Model or Compartment object.

If you define a reaction within a model object 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.

If you specify a compartment object as input, the newly-created compartment is then added as a subcompartment. The parent model is the model that contains the owning compartment.

Name of the compartment object, specified as a character vector or string scalar.

Data Types: char | string

Value of the compartment, specified as a positive scalar.

Data Types: double

Version History

Introduced in R2007b

expand all