Iterating through struct fieldnames in MATLAB
My question is easily summarized as: "Why does the following not work?" teststruct = struct('a',3,'b',5,'c',9) fields = fieldnames(teststruct) for i=1:numel(fields) fields(i) teststruct.(fields(i)) end output: ans = 'a' ??? Argument to dynamic structure reference must evaluate to a valid field name. Especially since teststruct.('a') does work. And fields(i) prints out ans = 'a' . I can't get my head around it. You have to use curly braces ( {} ) to access fields , since the fieldnames function returns a cell array of strings: for i = 1:numel(fields) teststruct.(fields{i}) end Using parentheses