MATLAB: Extracting everything from a structure

fieldnamesMATLABstructstructures

Is there a built in function to extract everything from a structure?
For example if I have a structure:
struct_name.struct_element1 = 7;
struct_name.struct_element2 = 'abc';
Then later I want create variables for every element of struct_name but I'm unaware of how many elements are in "struct_name" and what their names are. I wrote the following code to solve my problem but I feel there might be a more elegant solution or a built in function:
struct_field_names = fieldnames(struct_name);
for k = 1:length(struct_field_names)
eval([struct_field_names{k}, ' =...
struct_name.',struct_field_names{k}, ';']);
end

Best Answer

Ahh I searched more rigorously and found this discussion: