Skip to content

vlt.data.flattenstruct

  FLATTENSTRUCT - flatten a structure so that substructures are fields

  SF = vlt.data.flattenstruct(S, [PREFIX])

  Returns a flatten structure where any substructures are renamed to be fields
  of the structure S. 

  For example, if a structure A has fields AA and AB, and AA is a structure
  with fields AAA and AAB, then SF will have fields {'A__AA__AAA','A__AA__AAB','A__AB'}.

  If a substructure is a structure array with more than one element, then the entry number
  will be prepended to the field name.

  There is a chance that the function will not be able to flatten a structure array,
  if say S(1).field1 is a scalar and S(2).field1 is a structure. Then, the fields of SF(1)
  and SF(2) would differ, which will be an error.

  If PREFIX is provided, it will be pre-pended to to the structure names.

  Note: FLATTENSTRUCT is not recommended.  Fieldnames have a limit of 63 characters.
  This function may create truncated fields. Instead, see FLATTENSTRUCT2TABLE.

  Example:
     A = struct('AA',struct('AAA',5,'AAB',7),'AB',2);
     SF = vlt.data.flattenstruct(A);