simBiology exported model simulation output not in the same order as `InitialValues`

조회 수: 1 (최근 30일)
Hello,
I'm using a SimBiology exported model and I need to get the last value of a simulation and use it as initial condition for a following simulation (with different parameters, or dosing information), here is an example of what I need to do:
[t, y, names] = simulate(exported_model);
exported_model.InitialValues = y;
[t, y, names] = simulate(exported_model);
The problem is in the second line of the code as, surprinsingly, the order of the variables in y is not the same as the order in InitialValues. Currently, I'm performing a search for the appropriate index in names and using `exported_model.getIndex` to update each element of InitialValues. But this approach is suboptimal, it takes more than 1min to go over the entire array of initial conditions.
Is there any way to ensure that the output of model simulations come in the correct order? Or what would be the optimal approach here?
Thank you
  댓글 수: 1
Valentina Vasic
Valentina Vasic 2023년 2월 2일
Hallo Paulo,
I have never tried it, I usually use your method, but I never needed to do double simulation. Maybe this can give you a hand. You have to go to the Examples.
An easier and faster method I don't think there is, but here is some advice.
Best,
Valentina

댓글을 달려면 로그인하십시오.

채택된 답변

Fulden Buyukozturk
Fulden Buyukozturk 2023년 2월 2일
Hello,
exported_model.InitialValues lists all of exported_model's editable objects which is by default everything (compartments, species, parameters) whereas simulate(exported_model) returns states in the order of model's statesToLog, which is by default only non-constant quantities.
If you specify editable objects and statesToLog to be the same during model export, the order of quantities should be the same. Please see below for an example.
m = sbmlimport('lotka');
% define states for editable objects and statesToLog
states = sbioselect(m,'Name',{'y1','y2'});
% set statesToLog
m.getconfigset.RuntimeOptions.StatesToLog = states;
% export model specifying editable objects
em = export(m,states);
[t,y,names] = simulate(em);
{em.ValueInfo.Name}'
ans = 2×1 cell array
{'y1'} {'y2'}
names
names = 2×1 cell array
{'y1'} {'y2'}
Fulden
  댓글 수: 1
Paulo
Paulo 2023년 2월 3일
Thank you for your answer,
Adding the following line did the trick:
m.getconfigset.RuntimeOptions.StatesToLog = states;

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2023년 2월 1일
편집: Fangjun Jiang 2023년 2월 1일
For a Simulink simulation, there are Inputs, Outputs and States. Usually, only States need initial values.
From "exported_model.InitialValues = y", it seems that you are assigning the Outputs of last simulation to the initial States of the next simulation. That is the problem. In general, Outputs will not be the same as the States, although they could be exactly the same.
There are ways to save the values of States and utilize it for the next simulation. See "States" and "Final states" in this doc.
web(fullfile(docroot, 'simulink/gui/data-import-export-pane.html'))
web(fullfile(docroot, 'simulink/ug/state-information.html'))
web(fullfile(docroot, 'simulink/ug/saving-and-restoring-simulation-operating-point.html'))
  댓글 수: 3
Fangjun Jiang
Fangjun Jiang 2023년 2월 1일
Based on the doc link below, it seems "names" in your code is the column labels of "y". I wonder if there is a column label for model.InitialValues.
If there is and the labels match but in a different order, then you could use ismember() to shuffle them to match.
https://www.mathworks.com/help/simbio/ref/simbiology.export.model.simulate.html
Paulo
Paulo 2023년 2월 1일
Yes, that is my current approach (something similar to it anyway), I'm getting the index from names using:
[~, i] = max(cellfun(@(x) strcmp(x, name), all_names));
I do something similar using exported_model.getIndex, and I'm able to correctly update the initial values, but it takes more than one minute to do so. And that is even after I defined an array that maps one set of indexes into the other, so I don't have to the search every time.
So I was wondering if there is a more efficient way of doing it.
Thank you,

댓글을 달려면 로그인하십시오.

커뮤니티

더 많은 답변 보기:  SimBiology Community

카테고리

Help CenterFile Exchange에서 Import Data에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by