How to plot categorical data to compare with SimBiology simulation result?
Ältere Kommentare anzeigen
Is there a way to extract a simbiology simulation result for one time point and then overaly the result to compare with actual data? I'd like to create something like this plot below. The x-axis in my case would represent different sections of tissue samples such as stomach or small intestine and all measuremets would be compared with simulation result from day= 5.

6 Kommentare
Arthur Goldsipe
am 9 Mär. 2022
Do you want to do this within the SimBiology Model Analyzer app? Or with some sort of script or function that you can run outside the app? Or something else?
Fearass Zieneddin
am 9 Mär. 2022
Arthur Goldsipe
am 9 Mär. 2022
I think there are a few underlying questions I can answer here. I think you're mostly asking about the aspects that involve SimBiology, so I'll focus on those (since I'm a developer on the SimBiology team). And I'll just discuss the different steps roughly in the order you might need to do them. I'm also assuming that you're using SimData objects to store your simulation results. Please add a comment if any of these assumptions are incorrect, or if you want additional clarification.
The first step is figuring out how to accurately get the simulation result for a particular species at a particular time. If you're directly simulating a SimBiology model, the simplest solution is probably to set OutputTimes to the desire time (or times). This will ensure that the reported simulation result uses the actual ODE solver to estimate the results at that specific time (typically using a high-order interpolant to interpolate between solver time points).
Another option is to use a SimFunction to perform the simulations. In that case you can just specify the desired times as the 4th input argument (t_output on the reference page).
If you already have simulation results stored in an array of SimData objects, you can use the resample method to get the results at a particular time (or times). That will likely require interpolation, and you may want to specify the method used for interpolation. (I personally default to 'pchip'.) Since it sounds like this is for a publication, I'd probably double-check that the interpolated values look reasonable by plotting them on top of original simulation results.
And if you are only interested in a subset of the species in your SimData, you can use the selectbyname method to select the specific species you're interested in for subsequent steps.
Lastly, you will likely need to get the actual numbers out of these SimData so that you can plot them. You can either directly access the Time and Data properties, or you can use the getdata method to extract these numbers.
After that, you will have numbers in a cell array, and you can plot them however you want. If you have questions about those steps, it might be easiest to put them in a new MATLAB Answers question.
Fearass Zieneddin
am 9 Mär. 2022
Bearbeitet: Fearass Zieneddin
am 9 Mär. 2022
Arthur Goldsipe
am 9 Mär. 2022
Oh, first of all, apologies for posting an answer as a comment. I meant to post the above as an answer. But maybe that's irrelevant since I didn't understand your question correctly.
Sadly, I'm still a little unclear on exactly what you need help with. Could you provide sample data and/or code that illustrates the problem? Something like "Here's sample data. Here's the code I've written so far. And here's a sketch of what I'd like the plot to look like for this example." You've certainly described those things at a high level, but it's hard to know what to suggest without a bit more detail.
If you have concerns over sharing anything publicly here, please feel free to contact me directly, or perhaps you could contact Technical Support.
Fearass Zieneddin
am 10 Mär. 2022
Bearbeitet: Fearass Zieneddin
am 10 Mär. 2022
Antworten (1)
Arthur Goldsipe
am 11 Mär. 2022
If I understand your question, you're primarily asking how to extract the simulation results at a specific time (for example, 5 days). It sounds like you already have the simulation results, which you obtained by calling sbiosimulate. I'm assuming your simulation time units are day. However, it's not clear to me whether you have those results as a SimData object or as numeric arrays. If you have the results in SimData you can estimate the results at 5 days using the resample method. If you have the results in numeric arrays, you can estimate the resutls at 5 days using the interp1 function. In both cases, I default to the pchip interpolation method. Here's some sample code.
t = 5;
% Case 1: SimData
simdata = sbiosimulate(model);
simdata1 = resample(simdata, t, 'pchip');
[~,x1] = getdata(simdata1);
% Case 2: Numeric arrays
[tManyTimes,xManyTimes] = sbiosimulate(model);
x2 = interp1(tManyTimes, xManyTimes, 5, 'pchip');
% Now plot the data
plot(t, x1, 'o')
plot(t, x2, 'o')
Kategorien
Mehr zu Import Data finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!