View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Recursively check fields of a structure exist

5.0 | 1 rating Rate this file 6 Downloads (last 30 days) File Size: 1.76 KB File ID: #28142 Version: 1.1

Recursively check fields of a structure exist



06 Jul 2010 (Updated )

Check fields of a structure exist at any depth. Can also check multiple field branches at any depth.

| Watch this File

File Information

This function will return true if the first input structure contains the field in the second input string and in turn that field has the field given in the third input string and so on. This allows A.b.c = 2; to be checked as:
ans =
Which would return false if either b is not a field of A or c is not a field of a.b

The other functionality of this function is that the existence of multiple fields at any depth can be determined by replacing a string input with a cell array of strings. e.g. A.b.c = 2;A.d.c = 2;
ans =
Which would have returned false if A did not have either field b or field d and those fields in turn did not have a field c.

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
02 Feb 2017 Roger Parkyn

Did exactly what I needed (whereas the built-in "exist" function doesn't handle structures).

22 Jul 2010 1.1

Improved the summary text

Contact us