MATLAB structfun supported function to generate code using MATLAB Coder. If you set the 'UniformOutput' parameter to false , then the output of structfun is a structure that has the same fields as the input. The value of each field is the result of applying the supplied function descriptor to the corresponding field in the input structure.
mystruct = struct('a',3,'b',5,'c',9); outstruct = structfun(@sin, mystruct, 'UniformOutput', false); outstruct = a: 0.1411 b: -0.9589 c: 0.4121
So, you can write a subfunction that contains the body of the loop in your example and pass the handle of this subfunction to the structfun call.
source share