How to save dynare results in loop into a specified matrix

I do a loop in which dynare run 100 times, at the same time I want save the same name series into a specified matrix. forexample,
for i=1:100
dynare <filename.mod>
k(i,:slight_smile: = y %y is series generated by dynare
end
I found it cannot work because dynare refreshs the workspace in matlab everytime, so result show k is not definded and cannot store the y.
who can help me to save dynare results very run into a fixed name matrix?

best regards
lizeze

not quite clear what u want to do.
i usually run loops within the mod file.
then matrices appear in the workspace, and those can be easily saved into our own arrays or matrices.

you can simply define a vector/matrix/structure with length N in the mod-file which stores the underlying results in each step n and (important) SAVES the object for each step as a mat-file so that you can obtain your object after the loop is done.

greets, tomi

Hi tomi,

It is not clear to me how to write loops within the mod file. Could you please post an example where you do this. I am particularly interested in running a loop in which dynare uses the parameter values from the posterior distribution saved in the matrix _mh_blck*.mat to calculate the policy and transition function under each new draw.

Thanks.
abhishek.