# Run with params from MATLAB

**URL:** https://forum.dynare.org/t/run-with-params-from-matlab/18762
**Category:** Stochastic simulations
**Created:** [23 August 2021 23:41 UTC](https://forum.dynare.org/t/run-with-params-from-matlab/18762 "2021-08-23T23:41:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mlam303](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/e95f7d/32.png) [@mlam303](https://forum.dynare.org/u/mlam303)
#### Post date: [23 August 2021 23:41 UTC](https://forum.dynare.org/t/run-with-params-from-matlab/18762/1 "2021-08-23T23:41:11Z")

</div>

I want to run a Dynare script from a MATLAB function, with flexible parameters. My ludicrously hacky way to do it so far is along the lines of:

```auto
function irf_dat = get_irf_data(alpha, beta)
    filename = 'RBC_IRF_matching_results.mat'
    delete filename

    dynare RBC_IRF_matching %Add alpha and beta param values here, somehow
    
    irf_dat_temp = load(filename).oo_.irfs.ghat_eps_g
    irf_dat = mean(irf_dat_temp)
end

```

(and this doesn’t even use alpha and beta!)

(a) How can I pass parameters to the Dynare script?  
(b) How can I overhaul this monstrosity, so it doesn’t have to actually write/read from data files?

The reason for all this: I want to be able to differentiate certain model outputs with respect to parameters (and compute a numerical Jacobian of the outputs)

Thanks! (and sorry if I’ve burnt your eyes out due to such hacky/awful code)

---

<div class="post-metadata">

### Author: ![mlam303](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/e95f7d/32.png) [@mlam303](https://forum.dynare.org/u/mlam303)
#### Post date: [24 August 2021 19:57 UTC](https://forum.dynare.org/t/run-with-params-from-matlab/18762/2 "2021-08-24T19:57:10Z")

</div>

@jpfeifer any ideas…? Help hugely appreciated if you have a moment

---

<div class="post-metadata">

### Author: ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)
#### Post date: [26 August 2021 13:36 UTC](https://forum.dynare.org/t/run-with-params-from-matlab/18762/3 "2021-08-26T13:36:12Z")

</div>

The inner part of your loop is essentially contained in

> <https://github.com/JohannesPfeifer/DSGE_mod/blob/master/RBC_IRF_matching/IRF_matching_objective.m>
