Code covered by the BSD License  

Highlights from
Get structure field names in recursive manner

4.66667

4.7 | 4 ratings Rate this file 10 Downloads (last 30 days) File Size: 3.04 KB File ID: #33262

Get structure field names in recursive manner

by Adam

 

13 Oct 2011

Returns the field names of a structure, include the field names of any "sub-structures".

| Watch this File

File Information
Description

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.

MATLAB release MATLAB 7.13 (R2011b)
Tags for This File  
Everyone's Tags
field, fieldnames, recursive, struct, structure
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
31 May 2013 Emil

Saved me from writing script myself... :)

27 Mar 2012 Chad Webb

Saved me the hassle of writing it. Worked great right out of the box. Haven't tested on arrays of structs yet, but meets my current needs. Thanks!

27 Mar 2012 Chad Webb  
23 Feb 2012 SpinMan

this function throws the following error when i try

s=fieldnamesr(a)

where a.b.c(1,1).d.e = 1
where a.b.c(2,1).d.e = 2
where a.b.c(3,1).d.e = 3

??? Dot name reference on non-scalar structure.

Error in ==> fieldnamesr at 95
if isstruct(eval(NAMES{i})) == 1

i get the same error with R2011a and R2008a.

23 Feb 2012 SpinMan  

Contact us