Solving model as part of fminsearch

Hi,
I am estimating the parameters of a DSGE model by matching the IRFs of an identified VAR model. The criterion function is the squared difference between the model IRFs and the IRFs of the VAR, and look for a way to speed up the estimation routine. I am using fminsearch to minimize the criterion, and fminsearch executes dynare to solve the model at each iteration, so each time dynare has to parse the model file which slows down the computation. Is there a way around this? For instance, would it be possible to somehow call fminsearch within the .mod file, and the execute only stoch_simul within the mod file?
Or, alternatively, would it be possible to avoid executing Dynare within fminsearch altogether, by working directly with the .m files dynare produces when it solves the model?
I should mention that none of the parameters to be estimated affect the steady state of the model.

Many thanks for your help!
Best,
Ansgar

I am working on an example, but it will take a day or two.

I uploaded an example at github.com/JohannesPfeifer/DSGE_mod/tree/master/RBC_IRF_matching

Hi Johannes,
many thanks for this, I will have a look. Sorry for the late reply, I was away.
Best,
Ansgar