Pass a matlab string to a MACRO_VARIABLE

I would like to pass a Matlab string to a Dynare MACRO_VARIABLE.
I tried to follow verbatim this old post:
with no success:
The error message I receive is:

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

Am I doing something wrong? Any suggestions?


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

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.

xy =pwd
xy =

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. (1.5 KB)

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

xy =pwd

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

to construct the proper string substitutions.

Many thanks Johannes,

nice workaround with eval.

I did not think about it.