How exactly does SimBiology treat model objects?

5 ビュー (過去 30 日間)
Sam
Sam 2013 年 12 月 19 日
コメント済み: Sam 2013 年 12 月 19 日
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??

採用された回答

Arthur Goldsipe
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)
You can read more about copyobj in SimBiology here.
Best of luck, and post again if you have more questions!
-Arthur
  1 件のコメント
Sam
Sam 2013 年 12 月 19 日
That's exactly what I need. Thanks, Arthur!

サインインしてコメントする。

その他の回答 (0 件)

コミュニティ

その他の回答  SimBiology コミュニティ

カテゴリ

Help Center および File ExchangeExtend Modeling Environment についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by