configuration file for gui executable
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Walter Roberson
2011 年 5 月 5 日
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 件のコメント
Kaustubha Govind
2011 年 5 月 5 日
In addition, you can use UIGETFILE to let the user select such a configuration file at run-time.
参考
カテゴリ
Help Center および File Exchange で MATLAB Compiler についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!