# Pass a matlab string to a MACRO\_VARIABLE

**URL:** <https://forum.dynare.org/t/pass-a-matlab-string-to-a-macro-variable/22320>\
**Category:** Macro-language\
**Created:** [21 April 2023 12:42 UTC](https://forum.dynare.org/t/pass-a-matlab-string-to-a-macro-variable/22320 "2023-04-21T12:42:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![giovanma75](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/ed8c4c/32.png) [@giovanma75](https://forum.dynare.org/u/giovanma75)\
**Post date:** [21 April 2023 12:42 UTC](https://forum.dynare.org/t/pass-a-matlab-string-to-a-macro-variable/22320/1 "2023-04-21T12:42:40Z")

</div>

Dears,  
I would like to pass a Matlab string to a Dynare MACRO\_VARIABLE.  
I tried to follow verbatim this old post:  
[https://forum.dynare.org/t/include-file-stored-as-string-variable/4502/3?u=giovanma75](https://forum.dynare.org/t/include-file-stored-as-string-variable/4502/3)  
with no success:  
The error message I receive is:

```auto
Macro-processing error: backtrace...
- Unknown variable xy
- @#define: "command_line_defines" line 2, col 1-19

```

Am I doing something wrong? Any suggestions?

Thanks

---

<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:** [24 April 2023 12:36 UTC](https://forum.dynare.org/t/pass-a-matlab-string-to-a-macro-variable/22320/2 "2023-04-24T12:36:01Z")

</div>

Can you please provide the full code and the command you used.

---

<div class="post-metadata">

**Author:** ![giovanma75](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/ed8c4c/32.png) [@giovanma75](https://forum.dynare.org/u/giovanma75)\
**Post date:** [24 April 2023 13:59 UTC](https://forum.dynare.org/t/pass-a-matlab-string-to-a-macro-variable/22320/3 "2023-04-24T13:59:24Z")

</div>

Thanks Johannes.  
So to streamline the issue I cooked up an ad hoc example to avoid posting info of restricted nature.  
In the attached zip you find a mainfile and a subdirectory labelled src with a linearized RBC model.  
The purpose of the mainfile is to define the path where the model is located.

If I invoke dynare with no -D options the model executes fine because in that case fullpath is defined by concatenating two dynare strings.  
Alternatively, if I retrieve my current working directory in the Matlab command window and invoke dynare with -Dpath I receive an error message.

> Blockquote  
> xy =pwd  
> xy =  
> ‘C:\tests\dynare’
> 
> > dynare mainfile -Dpath=xy  
> > Starting Dynare (version 6-unstable-2022-11-30-1453-d574705b).  
> > Calling Dynare with arguments: -Dpath=xy  
> > Starting preprocessing of the model file …  
> > Macro-processing error: backtrace…  
> > Unknown variable xy  
> > @#define: “command\_line\_defines” line 1, col 1-18  
> > Error using dynare  
> > Dynare: preprocessing failed

My understanding is that dynare does not recognize the xy character array.  
Of course the intention of being able to pass a matlab string to dynare goes beyond this example, but I hope this is sufficient for you and the community to help me understand what I am doing wrong.

Thanks.  
[dynare.zip](https://forum.dynare.org/uploads/short-url/kMof9foE86pnoz4w8laQf6mdN5p.zip) (1.5 KB)

---

<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:** [24 April 2023 17:14 UTC](https://forum.dynare.org/t/pass-a-matlab-string-to-a-macro-variable/22320/4 "2023-04-24T17:14:41Z")

</div>

That’s because the command line treats `xy` as a string. Use

```auto
xy =pwd

eval(['dynare mainfile -Dpath="' xy '"'])

```

to construct the proper string substitutions.

---

<div class="post-metadata">

**Author:** ![giovanma75](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/ed8c4c/32.png) [@giovanma75](https://forum.dynare.org/u/giovanma75)\
**Post date:** [25 April 2023 09:07 UTC](https://forum.dynare.org/t/pass-a-matlab-string-to-a-macro-variable/22320/5 "2023-04-25T09:07:53Z")

</div>

Many thanks Johannes,

nice workaround with `eval`.

I did not think about it.

Best,

Massimo
