In a simbiology model, I use a spline function in a matlab .m function to set the value of a variable parameter. For example, the assignment rule might be: glucose = forced_glucose(time) The function is called a lot, and I'd like to minimize overhead. The data for the spline is in an xlsx file, and I'd like the function to only read the file once, and then retain the data in memory until I clear the function. Using the following works very well when one is running the model and developing stuff and testing constructs:
function glu = forced_glu(time)
raw = xlsread('my data file.xlsx')
pp = spline(raw(:,1),raw(:,2));
glu = ppval(pp,time);
Unfortunately, when one uses sbiofit, a warning is flagged noting that the model could not be accelerated. Apparently this is a limitation in the accelerate function, and is not surmountable. The limitation IS noted in the documentation set for "accelerate" where one is warned not to use persistent variables in functions used by simbiology, but there is no warning in the docs for "persistent".
I've been goofing around a bit trying to see if the global construct would work. There were a few glitches in my approach. I thought that someone might have run into this. Is there a way to ensure that a function used in simbiology rate expressions has a way to initialize on the first call, and to keep a structure (the piecewise polynomial structure 'pp') in accessible memory while running the model? I really don't want to process date into splines every call (several calls per time point).
In MATLAB, I could make the function use the pp as both an input and an output argument. But would that work with SB repeat assignment rules? Can I say [simbio_parameter_value pp] = forced_glucose(time,pp), and have the output pp stored in matlab memory?