Main Content

copyobj

Copy SimBiology object and its children

Description

copiedObj = copyobj(modelObj) makes a copy of a SimBiology model object modelObj and returns the copied model object copiedObj. The function also sets the Parent property of the copied model object to the root object.

copiedObj = copyobj(object,parentObj) makes a copy of a SimBiology object and returns the copied object. The function also sets the Parent property of the copied object to parentObj.

One exception is that if both object and parentObj are compartments, the Owner property of the copied object is set to parentObj instead.

example

copiedObj = copyobj(object,parentObj,conflictOption) specifies how to handle naming conflicts. (since R2024a)

example

Examples

collapse all

Create a model object and add a reaction.

m1 = sbiomodel("m1");
c1 = addcompartment(m1,"c1");
r1 = addreaction(m1,"a -> b");

Create a copy of the reaction object and add it to another model.

m2 = sbiomodel("m2");
r1copy = copyobj(r1,m2);

Create a copy of species a in the same compartment using the "force" option. The function adds the postfix "_1" to the name of the copied species to resolve the naming conflict.

a = m1.Species(1);
a_copy = copyobj(a,c1,"force")
a_copy = 
   SimBiology Species Array

   Index:    Compartment:    Name:    Value:    Units:
   1         c1              a_1      0               

Input Arguments

collapse all

SimBiology model component, specified as a Model, Compartment, Reaction, KineticLaw, or Root object.

If the input object is...parentObj must be...

Configset, Event, Reaction, Rule, RepeatDose, ScheduleDose, Variant, or Observable object

Model object

Compartment object

Compartment or Model object

Species object

Compartment object

Parameter object

Model or KineticLaw object

KineticLaw object

Reaction object

Model object

Root object

SimBiology model, specified as a Model object.

Method to resolve naming conflicts, specified as a character vector or string. Valid options are:

  • "force" — The function copies the model component but renames the copied component if there is a naming conflict by appending "_N", where N is a positive integer. For example, when you try to make a copy of a species inside the same compartment, the "force" option creates a copied species, which has the same name as the original species with a postfix "_N". For details, see Guidelines for Naming Model Components.

  • "strict" — The function throws an error and will not copy the model component if there is a naming conflict.

Note

There are some exceptions for this option, and it works for a subset of model components.

  • Compartment, dose, event, observable, parameter, rule, species, and variant objects support this option.

  • Configset and reaction objects do not have this option, but the copied object and any reaction-scoped parameters are always renamed as needed.

  • Model and KineticLaw objects do not have or need this option.

Version History

Introduced in R2006a

expand all

See Also

| |