Page 1 of 1

macro variable and .mod inserted in .m

PostPosted: Wed Mar 11, 2015 6:11 pm
by rudy
Dear all,

For some reasons, I included my .mod in a matlab file .m.
However in my .mod I use macro variables
(for instance I use @#define VARshock = 0 or 1 which I use with a if condition to define whether my shocks have AR or VAR structure).
But I would like to define the value of my macrovariable (o or 1) in the .m, i.e "decide" in the .m whether my shocks have a VAR structure or not, without having to open and modify the .mod file. How could I do that?

I hope my question is clear enough.

Thank you in advance,

best regards

Rudy

Re: macro variable and .mod inserted in .m

PostPosted: Thu Mar 12, 2015 9:35 am
by jpfeifer
What you can do is write the definition statement
Code: Select all
 @#define VARshock = 0
into a txt file in your m-file using e.g.
Code: Select all
var_shock_indicator=1;
fid=fopen('par_def.txt','w+');
fprintf(fid,' @#define VARshock = %u \n',var_shock_indicator);
fclose(fid)

Then include this file in your mod-file using
Code: Select all
@#include "par_def.txt"

Re: macro variable and .mod inserted in .m

PostPosted: Thu Mar 12, 2015 10:59 am
by rudy
Dear Prof Pfeifer,

Thank you very much for your answer, your solution works well and it helped a lot!

(Just in case someone also want to use it, I had to write @#include "par_def.txt" - ie don't forget to put the filename into quotation marks).

BR

Rudy