Shorthand for sbioselect/set

2 次查看(过去 30 天)
Jim Bosley
Jim Bosley 2018-5-16
In running simbiology models using scripts, one often wants to change parameter values. For a single parameter (e.g. "p1") we can do this:
p1_h = sbioselect(m1,'Name','p1')
p1_h.value = 15.6; % or could also use
set(p1_h,'value',15.6)
Is there a more compact method of doing this? Something like
sbiosetparval(m1,'p1_h',15.6);
I guess I can write sbiosetparval.m, but is there a native function?

回答(2 个)

Florian Augustin
Florian Augustin 2018-5-17
Hi Jim,
Your wrapper looks like a good solution for conveniently changing individual parameter/species/etc. properties. Thanks for sharing it on MATLAB Answers. If you need to specify multiple values for different parameter/species/compartment, then a SimBiology Variant may be useful. For completeness, here is how you can do it:
v = sbiovariant('name of variant');
addContent(v, {'Parameter', 'p1', 'Value', 15.6});
addContent(v, {'Parameter', 'p2', 'Value', 4.7});
commit(v, m1);
Admittedly, I am not sure if this qualifies as a shorthand, but it may pay off if you want to change a whole set of values.
If your use case is changing some quantities' values before simulating a model, then I would recommend using a SimFunction :
% Assuming you want to simulate a species S, without dosing,
% subject to specifying different values for parameter p1:
simFunction = createSimFunction(m1, 'p1', 'S', []);
% Simulate species S for parameter value 15.6 from time 0 to 10:
simData = simFunction(15.6, 10);
Best,
-Florian
  1 个评论
Jim Bosley
Jim Bosley 2018-5-17
编辑:Jim Bosley 2018-5-17
This is interesting and useful, Florian. I am using variants for different ICs, where a list is clearly implied. Naming the variant "Smith_ICs" tells the reader of my script that I'm using the ICs from the Smith article. Alle ist klar. But if I have a script I'm trying to duplicate, then someting that sets individual parameters shows the reader of the script or its published output, what I'm doing with the code.
That said, I do have some rules that switch between certain species from being calculated by ODEs, or set by a spline function. Unfortunately, variants don't include the active/inactive flags from rules! Still, I'll go over my code and see if I can use your ideas to simplify/clarify. But see my follow-on question below, please! :)

请先登录,再进行评论。


Jim Bosley
Jim Bosley 2018-5-17
编辑:Jim Bosley 2018-5-17
So I decided to write the code and am embarrassed with how simple it is. But a question arose. Here's the code:
function [flag] = sbiosetparvalue(modelobj,varname,value)
%%sbiosetvarvalue facilitates compact code for changing model parameters
% The inputs should be a simbiology model object, a character string with
% the parameter name, and a value to set the parameter to.
%
% testflag = sbiosetparvalue(m1,'kgm2',15.6);
%
flag = 1;
varhandle = sbioselect(modelobj,'Name',varname);
set(varhandle,'Value',value)
flag = 0; % admittedly weak/nonexistent error flagging
end
This works, but there's something about sbioselect use that bugs me. There can be duplicate names for things. So one could have in model m1, a compartment named cell, and a parameter named cell. Then sbioselect(m1,'Name','cell') returns a 2x1 handle array and not the desired handle for the variable. One can narrow down sbioselect's search list to parameters by using the object m1.Parameters. I'd like to do that in my subroutine, as a matter of idiotic compulsive fastidiousness. And I used to know this. If my function call is as above, how do I append the ".Parameters" onto the passed argument of modelobj? That is, something like:
varhandle = sbioselect({modelobj}.Parameters,'Name',varname) % or somesuch???
  1 个评论
Florian Augustin
Florian Augustin 2018-5-17
Hi Jim,
You can tell sbioselect to restrict the search to parameters:
param = sbioselect(modelObj, 'Name', varname, 'Type', 'Parameter');
This will find all parameters with matching name, including reaction-scoped parameters. If you do not want to find reaction-scoped parameters, you can replace the first input argument to sbioselect with modelObj.Parameters (assuming modelObj is not a vector of models).
Best,
-Florian

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Scan Parameter Ranges 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by