From: Stephen on 31 May 2010 06:48 Hello, I am a very new beginner with matlab and have been attempting to use it for my student project in systems biology. I have an m file which performs a Gillespie stochastic simulation. I would like to perform this simulation multiple times and store the results from each run in a matrix or array. The model file is in 1 m file, the simulator is in a 2nd. I am trying to write a 3rd m file that would call the model file, which in turn runs the simulator. The simulator stores the results in a matrix called sim_log. I was attempting to create a for loop that would run the simulator x number of times and store each run's sim_log matrix in a new matrix or array that I could later perform statistical analysis on (I would like to calculate signal to noise ratio for the results from all the sim_log matrices). Does anybody know how I can create a for loop that will call an m file a certain number of times and iteratively store the data from the sim_log matrix in a new matrix that I can later investigate? I attempted to write the following small bit of code, but it only runs once and I am not sure how to iteratively store the sim_log matrices in a new matrix. traj = 10; i=1; for i <= traj stochastic.m i+1 end Thanks for any assistance. :)
From: Zubin on 31 May 2010 06:55 What you can do is make a "for" loop for the amount of times you want to run the simulation. To save the results of your simulation in a separate matrix, just use the index "i" with a any variable to create an indexed array. You can do this by for i=1:100 %all the statements you want to run 100 times x(i)=simulation_output; end I'm not sure how your simulation.m is structured but you would want to make sure that it is a function and it's giving x(i) as an output. Just look up any simple function and you'll be able to figure out the syntax and you could convert your code into a function. Hope this helps.
From: us on 31 May 2010 06:58 "Stephen " <scheckley(a)gmail.com> wrote in message <hu0453$reu$1(a)fred.mathworks.com>... > Hello, > > I am a very new beginner with matlab and have been attempting to use it for my student project in systems biology. > > I have an m file which performs a Gillespie stochastic simulation. I would like to perform this simulation multiple times and store the results from each run in a matrix or array. > > The model file is in 1 m file, the simulator is in a 2nd. I am trying to write a 3rd m file that would call the model file, which in turn runs the simulator. The simulator stores the results in a matrix called sim_log. I was attempting to create a for loop that would run the simulator x number of times and store each run's sim_log matrix in a new matrix or array that I could later perform statistical analysis on (I would like to calculate signal to noise ratio for the results from all the sim_log matrices). > > Does anybody know how I can create a for loop that will call an m file a certain number of times and iteratively store the data from the sim_log matrix in a new matrix that I can later investigate? > > I attempted to write the following small bit of code, but it only runs once and I am not sure how to iteratively store the sim_log matrices in a new matrix. > > traj = 10; > i=1; > for i <= traj > stochastic.m > i+1 > end > > Thanks for any assistance. :) well... almost sure this did not even run once... anyhow, for i <= traj % must read for i=1:traj % then, there might(!) be a problem with stochastic.m; % is it % - a struct with field M(?): ok, keep it... % - a function you want to run: use stochastic; % <- without the extension M... altogether, read the getting started section of your ML doc... us
From: Arthur Goldsipe on 31 May 2010 19:22 "Stephen " <scheckley(a)gmail.com> wrote in message <hu0453$reu$1(a)fred.mathworks.com>... > Hello, > > I am a very new beginner with matlab and have been attempting to use it for my student project in systems biology. > > I have an m file which performs a Gillespie stochastic simulation. I would like to perform this simulation multiple times and store the results from each run in a matrix or array. > > The model file is in 1 m file, the simulator is in a 2nd. I am trying to write a 3rd m file that would call the model file, which in turn runs the simulator. The simulator stores the results in a matrix called sim_log. I was attempting to create a for loop that would run the simulator x number of times and store each run's sim_log matrix in a new matrix or array that I could later perform statistical analysis on (I would like to calculate signal to noise ratio for the results from all the sim_log matrices). > > Does anybody know how I can create a for loop that will call an m file a certain number of times and iteratively store the data from the sim_log matrix in a new matrix that I can later investigate? > > I attempted to write the following small bit of code, but it only runs once and I am not sure how to iteratively store the sim_log matrices in a new matrix. > > traj = 10; > i=1; > for i <= traj > stochastic.m > i+1 > end > > Thanks for any assistance. :) Hi Stephen, Are you doing your modeling and simulation using SimBiology? Although you will certainly benefit from learning some basic MATLAB usage like for loops and how to write a function, I have a couple of SimBiology-specific tips to help you as well. If your are simply running the same stochastic simulation multiple times, take a look at the function sbioensemblerun: http://www.mathworks.se/access/helpdesk/help/toolbox/simbio/ref/sbioensemblerun.html This function should do all the work for you, as long as you have a variable that contains the model you want to simulate. Also, as you learn some basic MATLAB funtionality, there is one key difference between SimBiology models and most other MATLAB data: SimBiology models remain in memory until they are explicitly deleted. This means you should be careful how you write your for loops. For example, the following bit of code will result in 1000 models being stored in memory (named Model 1, etc.): for j = 1:1000 m = sbiomodel(sprintf('Model %d', j)); % construct the model and perform a simulation end The variable m allows you to access Model 1000, but the remaining models can be found on something called the SimBiology root object: root = sbioroot; model1 = root.Models(1); Some users have run into memory problems because of this gotcha, so I wanted to warn you how to deal with it before it causes you any problems. In this particular example, you could rewrite the code like this: for j = 1:1000 m = sbiomodel(sprintf('Model %d', j)); % construct the model and perform a simulation delete(m); % Delete the model when you are done with it end I hope this is enough to help you get started. Good luck, and post again if you have more questions! -Arthur
From: Stephen on 1 Jun 2010 09:44 Hi, Thanks for the responses to my question. The suggested for loop code is working. I was dropped into it quite suddenly in my project when another modelling tool didn't suffice and I am working through a number of text books to gain a proper understanding of the language. "Arthur Goldsipe" <REMOVE.Arthur.Goldsipe(a)REMOVE.mathworks.com> wrote in message <hu1gav$9fs$1(a)fred.mathworks.com>... > "Stephen " <scheckley(a)gmail.com> wrote in message <hu0453$reu$1(a)fred.mathworks.com>... > > Hello, > > > > I am a very new beginner with matlab and have been attempting to use it for my student project in systems biology. > > > > I have an m file which performs a Gillespie stochastic simulation. I would like to perform this simulation multiple times and store the results from each run in a matrix or array. > > > > The model file is in 1 m file, the simulator is in a 2nd. I am trying to write a 3rd m file that would call the model file, which in turn runs the simulator. The simulator stores the results in a matrix called sim_log. I was attempting to create a for loop that would run the simulator x number of times and store each run's sim_log matrix in a new matrix or array that I could later perform statistical analysis on (I would like to calculate signal to noise ratio for the results from all the sim_log matrices). > > > > Does anybody know how I can create a for loop that will call an m file a certain number of times and iteratively store the data from the sim_log matrix in a new matrix that I can later investigate? > > > > I attempted to write the following small bit of code, but it only runs once and I am not sure how to iteratively store the sim_log matrices in a new matrix. > > > > traj = 10; > > i=1; > > for i <= traj > > stochastic.m > > i+1 > > end > > > > Thanks for any assistance. :) > > Hi Stephen, > > Are you doing your modeling and simulation using SimBiology? Although you will certainly benefit from learning some basic MATLAB usage like for loops and how to write a function, I have a couple of SimBiology-specific tips to help you as well. > > If your are simply running the same stochastic simulation multiple times, take a look at the function sbioensemblerun: > http://www.mathworks.se/access/helpdesk/help/toolbox/simbio/ref/sbioensemblerun.html > This function should do all the work for you, as long as you have a variable that contains the model you want to simulate. > > Also, as you learn some basic MATLAB funtionality, there is one key difference between SimBiology models and most other MATLAB data: SimBiology models remain in memory until they are explicitly deleted. This means you should be careful how you write your for loops. For example, the following bit of code will result in 1000 models being stored in memory (named Model 1, etc.): > > for j = 1:1000 > m = sbiomodel(sprintf('Model %d', j)); > % construct the model and perform a simulation > end > > The variable m allows you to access Model 1000, but the remaining models can be found on something called the SimBiology root object: > > root = sbioroot; > model1 = root.Models(1); > > Some users have run into memory problems because of this gotcha, so I wanted to warn you how to deal with it before it causes you any problems. In this particular example, you could rewrite the code like this: > > for j = 1:1000 > m = sbiomodel(sprintf('Model %d', j)); > % construct the model and perform a simulation > delete(m); % Delete the model when you are done with it > end > > I hope this is enough to help you get started. Good luck, and post again if you have more questions! > > -Arthur
|
Pages: 1 Prev: Using Imtool for DICOM 16-bit images in an executable GUI Next: Filtering a signal |