Main Content

Results for

Introduction
Comma-separated lists are really very simple. You use them all the time. Here is one:
a,b,c,d
That is a comma-separated list containing four variables, the variables a, b, c, and d. Every time you write a list separated by commas then you are writing a comma-separated list. Most commonly you would write a comma-separated list as inputs when calling a function:
fun(a,b,c,d)
or as arguments to the concatenation operator or cell construction operator:
[a,b,c,d]
{a,b,c,d}
or as function outputs:
[a,b,c,d] = fun();
It is very important to understand that in general a comma-separated list is NOT one variable (but it could be). However, sometimes it is useful to create a comma-separated list from one variable (or define one variable from a comma-separated list), and MATLAB has several ways of doing this from various container array types:
1) from a field of a structure array using dot-indexing:
struct_array.field % all elements
struct_array(idx).field % selected elements
2) from a cell array using curly-braces:
cell_array{:} % all elements
cell_array{idx} % selected elements
3) from a string array using curly-braces:
string_array{:} % all elements
string_array{idx} % selected elements
Note that in all cases, the comma-separated list consists of the content of the container array, not subsets (or "slices") of the container array itself (use parentheses to "slice" any array). In other words, they will be equivalent to writing this comma-separated list of the container array content:
content1, content2, content3, .. , contentN
and will return as many content arrays as the original container array has elements (or that you select using indexing, in the requested order). A comma-separated list of one element is just one array, but in general there can be any number of separate arrays in the comma-separated list (zero, one, two, three, four, or more). Here is an example showing that a comma-separated list generated from the content of a cell array is the same as a comma-separated list written explicitly:
>> C = {1,0,Inf};
>> C{:}
ans =
1
ans =
0
ans =
Inf
>> 1,0,Inf
ans =
1
ans =
0
ans =
Inf
How to Use Comma-Separated Lists
Function Inputs: Remember that every time you call a function with multiple input arguments you are using a comma-separated list:
fun(a,b,c,d)
and this is exactly why they are useful: because you can specify the arguments for a function or operator without knowing anything about the arguments (even how many there are). Using the example cell array from above:
>> vertcat(C{:})
ans =
1
0
Inf
which, as we should know by now, is exactly equivalent to writing the same comma-separated list directly into the function call:
>> vertcat(1,0,Inf)
ans =
1
0
Inf
How can we use this? Commonly these are used to generate vectors of values from a structure or cell array, e.g. to concatenate the filenames which are in the output structure of dir:
S = dir(..);
F = {S.name}
which is simply equivalent to
F = {S(1).name, S(2).name, S(3).name, .. , S(end).name}
Or, consider a function with multiple optional input arguments:
opt = {'HeaderLines',2, 'Delimiter',',', 'CollectOutputs',true);
fid = fopen(..);
C = textscan(fid,'%f%f',opt{:});
fclose(fid);
Note how we can pass the optional arguments as a comma-separated list. Remember how a comma-separated list is equivalent to writing var1,var2,var3,..., then the above example is really just this:
C = textscan(fid,'%f%f', 'HeaderLines',2, 'Delimiter',',', 'CollectOutputs',true)
with the added advantage that we can specify all of the optional arguments elsewhere and handle them as one cell array (e.g. as a function input, or at the top of the file). Or we could select which options we want simply by using indexing on that cell array. Note that varargin and varargout can also be useful here.
Function Outputs: In much the same way that the input arguments can be specified, so can an arbitrary number of output arguments. This is commonly used for functions which return a variable number of output arguments, specifically ind2sub and gradient and ndgrid. For example we can easily get all outputs of ndgrid, for any number of inputs (in this example three inputs and three outputs, determined by the number of elements in the cell array):
C = {1:3,4:7,8:9};
[C{:}] = ndgrid(C{:});
which is thus equivalent to:
[C{1},C{2},C{3}] = ndgrid(C{1},C{2},C{3});
Further Topics:
MATLAB documentation:
Click on these links to jump to relevant comments below:
Dynamic Indexing (indexing into arrays with arbitrary numbers of dimensions)
Nested Structures (why you get an error trying to index into a comma-separated list)
Summary
Just remember that in general a comma-separated list is not one variable (although they can be), and that they are exactly what they say: a list (of arrays) separated with commas. You use them all the time without even realizing it, every time you write this:
fun(a,b,c,d)
I'm trying to solve one problem in Cody, but a function 'fmincon' is not recognized by the online compiler. Is there any way to use functions in optimization toolbox in Cody?
I already solved some problems in Cody, why does he not increase my points or allow me to earn badges?
I need to put a number of problems on MATLAB cody under same Problem group, as many other people have done.
Can anyone please help me on this.

Hello

I would like to pulse an input species. I read in the forums that repeated assignments can be used for this, but I am not exactly sure how to implement this. This is the MATLAB code that resembles what I would like the input pattern to be:

t = 0:1/1e3:60;
d = [10:2:30]';
x = @rectpuls;
y = pulstran(t,d,x);
plot(t,y)
hold off
xlabel('Time (s)')
ylabel('Waveform')

Thanks for any help! Aaron

I created a problem in Cody that approximates e. To test the user's solution, I compare their solution to e. What I want to do instead is compare the user's solution to my reference solution. The question is how do I call the reference solution in the test suite?
This is currently my test suite.
sol=exp(1);
y_correct = playgame();
assessVariableEqual('y_correct',sol);
I created several problems recently in CODY. Some of them got removed automatically. I was curious as to why.
It is possible that the problems used latex in their description, so I am not sure if that was the reason they got rejected by the cody server.
I created some problems last night and created a group too. All those are now missing.
Also my ranking progress, activites, badges earned last night are missing too.
Hi all,
I hope everyone is doing well and keeping safe. I was wondering, are there any Cody challenges for Simulink these days?
I saw a post from 2015 (https://blogs.mathworks.com/simulink/2015/08/07/modeling-and-simulation-challenge-in-cody/) and it seems there was a Simulink or "Modeling and Simulation Challenge" problem group, but I couldn't find this group anymore. Perhaps I missing something?
Thank you beforehand.
Tungky

Hello, We would like to share one of our QSP models with non-modeler colleagues for them to play with. Is there a simple way to generate a standalone app from a SimBiology model, with sliders allowing the user to change various parameter values?

Thank you,

Abed

Hello, Does the 'sbiofit' function have functionality implemented for likelihood=based handling of BLoQ censored data, similar to functionality in NONMEM and other softwares? If not, are there plans to implement this?

Thanks,

Abed

I see this solution on the Cody solutions list. Solution 1949216
I am puzzled as to how this could possibly be rated as correct (size 48)
(BTW - I am pretty sure I saw this, or similar, before.)
function ans = fileread(varargin)
' ';
a=1;
b=3;
a=1;
b=3;a=1;
b=3;a=1;
b=3;a=1;
b=3; end

Hello,

I recently downloaded the GlobalSensitivityAnalysisApp. I am trying to perform a GSA using a simbiology model. I try running the App, but I get the error "No Sobol Indices Available to Plot. Configure the Sobol section and click the Compute button." I'm not sure if there is a step I'm overlooking. I'm following the instructional video for this app on the Matlab website, and I'm not sure what Configure the Sobol section is referring to. Any guidance would be greatly appreciated.

It's pretty odd how a solution that uses more characters than usual can be the "leading solution" of a Cody problem and have the least size. Compare these two codes that find the sum of integers from 1 to 2^x, which one uses fewer characters, thus should be the better solution?
function y = sum_int(x)
regexp '' '(?@y=sum(1:2^x);)'
end
function ans = sum_int(x)
sum(1:2^x)
end

How can I add the value of the error for each estimated parameter?

Hi, all

Recently I read the book "Physiologically Based Pharmacokinetic (PBPK) Modeling and Simulations: Principles, Methods, and Applications in the Pharmaceutical Industry" and find this state,"Since the unbound concentrations in plasma and blood are expected to be the same, fub , fup , and R are related as follows: R=Cb/Cp=(Cub·fup)/(Cup·fub) and R=fup/fub". I don't know whether it is reasonable to generally assume unbound concentrations in plasma and blood to be the same since components in whole blood and plasma are not the same. Is it common to see this equality in real situation?

Thanks for comment.

Hello,

We're working with a vendor to expand one of our current models that's written in SimBiology, but that vendor doesn't have a license to SimBiology. It would be nice if there existed a "Simbiology Viewer" which can be downloaded as a free Matlab package, and which would allow one to view but not edit SimBiology models. Are there any plans for something like this in the future? Something like this would make it much easier to share our models with people who don't have a license to SimBiology.

On a similar note, does anyone have any advice on the best ways to share SimBiology models currently? I noticed there's some functionality to export the tables of reactions, parameters, species, etc., and there's also some functionality to export the model into SBML.

Thank you,

Abed

If a large number of fair N-sided dice are rolled, the average of the simulated rolls is likely to be close to the mean of 1,2,...N i.e. the expected value of one die. For example, the expected value of a 6-sided die is 3.5.
Given N, simulate 1e8 N-sided dice rolls by creating a vector of 1e8 uniformly distributed random integers. Return the difference between the mean of this vector and the mean of integers from 1 to N.
function dice_diff = loln(N)
A=randi([1,N],1e8,1)
M=mean(A)
B=1:N
m=mean(B)
dice_diff =abs(M-m);
end
Here is my code, but it can't work out as it needs too long time to creat A.

Hi, all friends,

I want to record the fraction of drug absorbed in each intestinal segment, so I define a set of parameters with rate rule like: AbFraction_Colon= ((PeffColon*2/organismRadiusColon+paracellularAbsorption*organismFluxMucosaSerosa/Colon)*Colon.DrugDissolved)*Colon/InitialDose The attached figure shows the simulation result that overall PK profile (purple) seems OK, but I don't know why the absorption fraction line (red) starts from value of 1. Does anyone know the cause?

By the way, I am using model modified from "generic PBPK model"

Thanks for comment.

Hi, all friends

I am dealing with a confusing NCA result. As this result shows, AUC_infinity=0.8537 (μg*h/mL), DM=1 (mg). CL should be equal to DM/AUC_infinity but why is the calculated result 2.4491? There is no dimension along with value so I do not know if I ignore anything.

Does any one can handle with this situation? Thanks very much. I also post my used data (i.v.).