Reading settings for an app from text file
Show older comments
I have designed an app for which I need to store some settings in a text file as shown in the attached example_file.ini.
In my mind the content of the file should be read into a multilevel struct with the fieldnames defined in the .ini file.
From this example the output should be as written in code below, but I can't seem to get my head around how to create a reader function for it. If you have any ideas please share them in comments - or if you have a link to a fileexchange function (of if you're making a custom one for me) which does exactly that, please submit as an answer.
If I'm completely off track and you have a brilliant other solution how to create customizable and readable defaultsettings for various properties in an app for someone who doesn't understand the app designer (or actually the app will be compiled and this settings file needs to be 'besides it') - let me know in comments.
settingsstruct.Project = struct;
settingsstruct.Users = struct;
settingsstruct.Result = struct;
settingsstruct.Project.Subproject = struct;
settingsstruct.Project.Subproject.ID12345 = struct;
settingsstruct.Project.Subproject.ID12345.datafile = "thisfilecontainsdata.mat";
settingsstruct.Project.Subproject.ID12345.Interpreter = struct;
settingsstruct.Project.Subproject.ID12345.Interpreter.decimal = ".";
settingsstruct.Project.Subproject.ID12345.Limits = struct;
settingsstruct.Project.Subproject.ID12345.Limits.datasize1 = 100;
settingsstruct.Project.Subproject.ID12345.Limits.datasize2 = 10000;
settingsstruct.Project.Subproject.ID23456 = struct;
settingsstruct.Project.Subproject.ID23456.datafile = "thisfilecontainssomeotherdata.mat";
settingsstruct.Project.Subproject.ID23456.Interpreter = struct;
settingsstruct.Project.Subproject.ID23456.Interpreter.decimal = ",";
settingsstruct.Project.Subproject.ID23456.Limits = struct;
settingsstruct.Project.Subproject.ID23456.Limits.datasize1 = 10;
settingsstruct.Project.Subproject.ID23456.Limits.datasize2 = 100000;
settingsstruct.Users.Admin = ["Admin1""Admin2"];
settingsstruct.Users.Operator = ["Operator1""Operator2""Operator3"];
settingsstruct.Result.Averaging = struct;
settingsstruct.Result.Averaging.AvgN = 3;
Accepted Answer
More Answers (0)
Categories
Find more on JSON Format in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!