I have a multi-level struct and I would like to change the value for a field in one of the lower levels. The path to the field name is stored in a char array. For example,
>> fieldToChange = 'levelA.levelB.levelC.myField';
Usually, when the name of a field is stored in a variable, I can access it using parenthetical notation:
>> fieldName = 'levelA';>> myStruct.(fieldName) = 0;
However, when I use that notation with 'fieldToChange', I see the error below:
>> fieldToChange = 'levelA.levelB.levelC.myField';>> myStruct.(fieldToChange) = 0;Reference to non-existent field 'levelA.levelB.levelC.myField'
How do I access the field at the location stored in 'fieldToChange'?
Best Answer