Category

Monday, May 28, 2012

Hi guys,

Well, global variables are not encouraged in MATLAB. But, sometimes you may want to initialize an object with some parameters and you would like to access some global parameters as well.

Here is what you can do.
  • Create a file (say Params.m) for storing such global variables.
          insert your global parameters like this:
          global MY_GLOBAL; MY_GLOBAL = 1;
  • Next, include this file in your main .m file.
          Params;
  • Afterthat, in your class file, inside the constructor function (or any other function)
          global MY_GLOBAL;
          obj.xyz = MY_GLOBAL;

done!


No comments:

Post a Comment