Add new line in .ini file

I'm trying to set the properties of a class by loading the contents of the initialization file in a class method.
Source for INI class (https://www.mathworks.com/matlabcentral/fileexchange/55766-ini).
classdef setting
properties(Constant)
test_graph = settings_utils.data.test_graph;
end
methods(Static)
function data = load_data
I = INI('File','input.ini');
I.read();
data = I.get('UserData'); % struct
end
end
end
example.ini includes the following
[UserData]
test_graph = struct( ...
'test1', false, ...
'test2', false, ...
'test3', false)
>>> settings.test_graph
ans =
'struct(...'
I would like to know how to add new line in .ini files.
I tried to add `...` which is how I add multiple lines in .m files. But this doesn't work i.e the struct is not read correctly from the .ini file; it is read as a string.

6 Comments

This code will not write anything to a file. After more than one hundred questions you should know to give a bit of context. I should not have to read your last several questions to guess what ini file you might be talking about and what format it might have.
My mistake, I will add more details.
@Rik please have a look
@Deepa Maheshvare: INI does not appear to be a MATLAB function/class. Did you write it? Or is it from a third-party?
Please give a link to the INI function/class.
Deepa Maheshvare
Deepa Maheshvare on 19 Dec 2021
Edited: Walter Roberson on 19 Dec 2021
I'm sorry, I forgot to add the reference.
Please find the INI class link here

Sign in to comment.

Answers (1)

Jacob Mathew
Jacob Mathew on 16 Feb 2024
Edited: Jacob Mathew on 16 Feb 2024
I was able to reproduce the difficulty you were facing using the same INI Add on in MATLAB R2021a. However, even after multiple approaches of declaring multi-line values, the read function of this specific Add On only reads a single line.
A possible workaround is to write the entire struct in a single line in the INI file as follows:
% input.ini file
[UserData]
test_graph = struct('test1',false,'test2’,false,’test3’,false)
The documentation for struct can be found here:
Then when you perform the read operation, it will be read as a struct. The following code and screenshot below demonstrate the same:
% MATLAB Code to read from the INI file
File = 'input.ini';
I = INI('File',File);
I.read();
data = I.get('MyData');

Categories

Products

Release

R2021a

Tags

Asked:

on 19 Dec 2021

Edited:

on 16 Feb 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!