How exactly does SimBiology treat model objects?
6 次查看(过去 30 天)
显示 更早的评论
I need to create a series of SimBiology models with similar attributes, so I am creating a new model equal to my original model so that I can make some small tweaks to the new object, using a MATLAB script. I'll call the original model model and the new model model2:
model2 = model;
Now suppose I want to simply change the name of one of the species in model2, say, from E to E1:
model2.species(1).Name = [model2.species(1).Name num2str(1)];
And certainly species 1 of model 2 has a 1 appended on to the end of its name. My problem is that my code makes this change for my original model as well, even though I have made no mention of it in my code. So if I call 'model.Species' and 'model2.Species', I obtain exactly the same result:
Index: Compartment: Name: InitialAmount:
1 unnamed E1 0
Can anyone provide any issue into this issue; specifically, how do I prevent the original model's attributes from changing when I change model2's? It seems that model2 is somehow both a SimBiology object and a pointer to model??
0 个评论
采纳的回答
Arthur Goldsipe
2013-12-19
Hi Sam,
As you discovered, a SimBiology model is a "handle" object. This means that your variables model and model2 both refer to the same model, and any change you make via model2 also affects the variable model. In fact, all of the objects in a SimBiology model (species, parameters, reactions, etc.) are handle objects. You can get more information about handle versus value objects in MATLAB here.
You have to do something special whenever you want to copy a handle object. To copy a SimBiology model, you need to do the following:
model2 = copyobj(model)
Best of luck, and post again if you have more questions!
-Arthur
更多回答(0 个)
社区
更多回答在 SimBiology Community
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Extend Modeling Environment 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!