Run a m-file (which simulates a Markov chain) multiple times and store the results
    7 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Sara
 el 19 de Feb. de 2016
  
I wrote an m-file (called Markov) with simulates a Markov chain and creates time-series for a number of variables on the basis of that particular history of shocks realized.
I need to run the code for 1,000 times and store the results, so that I can calculate some statistics such as the mean standard deviation of my variables.
Thanks in advance.
0 comentarios
Respuesta aceptada
  Ralf
      
 el 19 de Feb. de 2016
        Can't you simply use a for Loop like this one?
for i=1:1000
   result{i} = markov(input{i});
end
% Then you can process the results here
6 comentarios
  Stephen23
      
      
 el 22 de Feb. de 2016
				
      Editada: Stephen23
      
      
 el 22 de Feb. de 2016
  
			It seems that you have written a script. Functions are better for various reasons (own workspace, function encapsulation, debugging). You can easily turn your script into a function by writing this on the first line:
function out = Markov
... your code here
where the variable out is the name of whatever variable you have define inside your code that you want the function to return. You can then call this function in a loop:
result = zeros(1000,1000);
for k =1:1000
    result(k,:) = Markov();
end
Read more about the differences between functions and scripts here:
In general functions are a much more robust and a better way to write code :
Más respuestas (0)
Ver también
Categorías
				Más información sobre Markov Chain Models en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


