MATLAB: Access data in a nested struct nested structstring find Hello, I have a struct with several levels. For example: s.L1.L2.L3 what would be the most efficient way to look for a string in Level L3? Thanks! Best Answer Let us name your string field inside L3 as 'Name'. If you want to access data inside a nested struct, You can do it by, s.L1.L2.L3.Name = 'String' For more information on accessing nested structs refer to the following: https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-nested-structures.html Related SolutionsMATLAB: Creating a structure in for loop Use the syntax shown in the MATLAB documentation:>> a = {'see','why'};>> KPI = {'L','L2','L3'};>> S.(a{1}).(KPI{1}) = 5;>> S.see.Lans = 5Read more:https://www.mathworks.com/help/matlab/matlab_prog/generate-field-names-from-variables.html MATLAB: Access to nested structs Use getfield with a comma-separated list:a.b.c.d = pi;x = {'b','c','d'};getfield(a,x{:})ans = 3.1416https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.htmlhttps://www.mathworks.com/matlabcentral/answers/320713-how-to-operate-on-comma-separated-lists Related QuestionNested Struct Preallocated MemoryConvert nested struct to matrixAccessing variable in struct using stringStruct arrayLooping over inputs provided by structure
Best Answer