Hello,
I have a text file containing a series of recordings (separated by a specific marker), and that each contains some fields of a structure (one structure field per line). Not all fields are present in a given recording (then those fields are assumed to have their default value); and there is no specific order in the various fields of a recording. The number of fields might also be expanded in the future, and I would like the text-data-field-reader to stay fine against any later expansion of the structure.
So the goal is to get the data from those recordings and the appropriate fields, as read from the text file.
An example of text file is given below:
%newRecord
TheStruct.field4 = 'hello';
TheStruct.fiels3 = 2.0;
%newRecord
TheStruct.field1 = 1;
TheStruct.field5 = '!';
%newRecord
(...)
What would be the simplest way to read such file, and fill the data into an array of structures TheStruct ?
An unsuccessfull try:
After reading one line at a time and identidying a new recording (%newRecord),
I went reading one line at a time (until the following %newRecord, or the end of the file)
Each new line 'NewLine' is split, eg.:
B= strtrim(split(NewLine,'=')); and then use B(1) to identify which field should be filled with B(2).
... Anyways, after having defined a structure TheStruct, and filled it with default values, and then extracted from the file say 'TheStruct.field5' :
genvarname('TheStruct.field5') gives an error
Furthermore, 'genvarname' is expected to be deprecated soon, so I would rather prefer to stay away from it.
What would be a robust yet simple solution to the problem exposed above ?
Thanks,