MATLAB: Performing Action to ALL ‘struct’ Variables

actionallstructvariables

Is there a way to perform the same action on several variables of type 'struct'?
In my case, I have 30 separate 'struct' variables (with non-logical names), and each of them contains a single vector of 200 elements. I only want to deal with the second half of these elements so I need something like:
struct_name = struct_name.data(100:end)
But need to keep the name of the struct variable intact. Does anyone have any suggestions?
I hope this made sense!

Best Answer

% Create several structures with different names...
structn.dat = 1:10;
structm.dat = 1:10;
structk.dat = 1:10;
% Now edit the data.
save mystructs structn structm structk
X = load('mystructs');
F = fieldnames(X);
for ii = 1:length(F)
X.(F{ii}).dat = X.(F{ii}).dat(5:10);
end
% Check
X.structm.dat