configuration file for gui executable
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I created from a gui an executable with the Matlab Compiler. Now a configuration file has to be created containing the strings of different edit fields and the values for checkboxes and pushbuttons.
In the noncomiled case one can create a m-file script containing different variable definitions, eg.:
% Script-file init1.m:
variable = 'Text';
% Matlab-program test1.m:
init1 % read variable
msgbox(variable) % apply variable
This is impossible for the compiled program.
Question:
How can I read a configuration file from a executable?
Best regards,
Mario
0 comentarios
Respuestas (2)
Walter Roberson
el 5 de Mayo de 2011
There will be some difficulties in getting the right directory name to find the configuration file, but there are others here that know exactly how to get that part to work.
You will have to parse the configuration file, such as by using
fid = fopen(ConfigFileName,'rt');
inconfig = textscan('%s %*[=] %[^\n]', 'CommentStyle', '%');
fclose(fid);
Then inconfig{1} should be a cell array of strings that are the variable names, and inconfig{2} should be a cell array of strings that are the corresponding values. You would need to examine the values further to determine whether they are valid numbers or strings or whatever you want to allow, and after validation you would use str2double() and the like to extract the corresponding value.
If instead of independent variables, you use a structure of configuration variables, then after validating that the variable names are valid (and known) identifiers, you could use dynamic structure field names to do the assignments.
Another approach to this all, especially with more complicated initialization schemes, is to use regexp to do the parsing of the configuration file.
1 comentario
Kaustubha Govind
el 5 de Mayo de 2011
In addition, you can use UIGETFILE to let the user select such a configuration file at run-time.
Ver también
Categorías
Más información sobre MATLAB Compiler en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!