I would like to set in a file all constant,parameters and then I can access from another class to any variable
for example const file const.m
FILE='file';
EDIT='edit';
COLOR_RED ='red',
COLOR_BLUE ='Blue'
START ='Start'
.....
...
and from any other files if I would like to access to any variable :
a = const.EDIT
so that I haven’t to set a =’file’ in each file.
How could I do that with matlab ?
how could also use enumeration ?
You don’t need a struct just use the save command: http://www.mathworks.com/help/techdoc/ref/save.html and specify which workspace variables you want to save. If there are small like in your example, they will be easy to read in notepad for access not in matlab. In matlab just use the load function.
For example create two variable in matlab:
now type
this should create a file called myData.mat in your current working folder.
Now in another Matlab script you want to set a variable to have the value you saved as Var1 so you can go
And you can easily edit the values in the .mat file in a text editor such as notepad or gedit (or emacs or ms word or whatever) if you add the -ascii parameter when saving.
But you can also rewrite a variable by using save() again and specifying the variable name.