One way to flatten a struct in Matlab is to use the struct2cell
function to create a cell array of the struct's fields, then use cat
to concatenate those cell arrays into a single cell array. Here's an example:
main.m126 chars6 lines
This will create a single column cell array flat
containing the contents of all fields in the struct, in the order they appear in myStruct
. Note that if your struct contains nested structs, this method will not automatically flatten them - you'll need to process them in a separate step if needed.
gistlibby LogSnag