Get structure field names in recursive manner

version 1.0.0.0 (3.04 KB) by Adam
Returns the field names of a structure, include the field names of any "sub-structures".

2.3K Downloads

Updated 13 Oct 2011

View License

NAMES = fieldnamesr(S) returns a cell array of strings containing the structure field names associated with s, the structure field names of any structures which are fields of s, any structures which are fields of fields of s, and so on.

NAMES = fieldnamesr(S,DEPTH) is an optional field which allows the depth of the search to be defined. Default is -1, which does not limit the search by depth. A depth of 1 will return only the field names of s (behaving like FIELDNAMES). A depth of 2 will return those field names, as well as the field names of any structure which is a field of s, and so on.

NAMES = fieldnamesr(...,'full') returns the names of fields which are structures, as well as the contents of those structures, as separate cells. This is unlike the default where a structure-tree is returned.

NAMES = fieldnamesr(...,'prefix') returns the names of the fields prefixed by the name of the input structure.

NAMES = fieldnamesr(...,'struct') returns only the names of fields which are structures.

Cite As

Adam (2022). Get structure field names in recursive manner (https://www.mathworks.com/matlabcentral/fileexchange/33262-get-structure-field-names-in-recursive-manner), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!