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, = 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?

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.

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.

I am writing a mode file PPsd.mod (11.6 KB)
with a for Loop statements:

ii=0:0.1:2;
save_results =zeros(length(ii));
for ii=1:length(ii)
dynare PPsd noclearall;
save_results(ii,1) = oo_.osr.objective_function;
end
save save_results;
However ,the output is different from what I calculate.For example,when ii=2,objective_function is 0.00196616(BUT is 0.0013 for LOOP).
Is there something wrong with my for Loop statements?

I solved the problem.It should be:
iis=[0:0.1:2];
save_results =zeros(length(iis));
for i=1:length(iis)
ii=iis(i);
dynare PPsd noclearall;
save_results(i) = oo_.osr.objective_function;
end
save save_results;