MATLAB: Can I define Capacity for compartment by using parameters in SimBiology model

SimBiology

Best Answer

You can do this by creating a rule that sets the value of the compartment's capacity. E.g.
m = sbiomodel('example');
compartment = m.addcompartment('C');
m.addparameter('A', 'Value', 2);
m.addparameter('B');
m.addrule('C = A/B');
This creates an Initial Assignment, i.e. the expression A/B gets evaluated before the simulation starts.
If A and/or B are changing over time (during the simulation) then:
compartment.ConstantCapacity = false;
m.addrule('C = A/B', 'RuleType', 'RepeatedAssignment');
instead makes changes to C as the simulation runs. Note that for this case the compartment must be configured to be non-constant as shown above otherwise an error will indicate that 'compartment' cannot be modified during the simulation.