MATLAB: Extracting fields from structures with varying names.

structuresworkspace

Hi I have several structures on my workspace. Their names are unrelated (e.g. "data_23_200_600_451", "data_58_588_154_289" etc.), but they all have identical field names. The tricky names of the structures make it difficult to extract the the same field in all structures using a loop (i.e. the names are not 'data_1', 'data_2' etc.) Is there any other method to automatically extract the fields from these structures? Thank you!

Best Answer

Use this example to see if it helps to resolve your issue
clear;
data_23_200_600_451=struct('strings',{{'hello','yes'}},'lengths',[5 3]);
data_58_588_154_289=struct('strings',{{'abc','efg'}},'lengths',[5 3]);
save;
Vars=load;
StructNames=fieldnames(Vars);
for k=1:numel(StructNames)
Vars.(StructNames{k}).strings
end