Exporting simulation results inside a matlab function

Hi all,
I am creating a function in matlab and inside it the model is executed several times but the results are not created in the workspace until the whole function finishes. This does not allow me to use the results of the models inside the function.
What can I do so that the Dynare outputs are produced inside the function?
Thanks for your help

It’s hard to tell without knowing the details or seeing the codes. But usually, you would pass the relevant variables as explicit function outputs back to the workspace.