isempty_field - Easily check whether a deeply nested field is empty or non-existent

This function checks if a field is empty/non-existent without needing its parent fields to exist

You are now following this Submission

tf = isempty_field(S,fname)

This function checks whether a field is empty/non-existent. It is particularly useful when we want to check whether a
deeply nested field is empty, but are unsure if the field and/or its parent fields exist. The functions "isempty" and "isfield" cannot readily be applied for this purpose, because they require the parent fields to exist.

For example, we have a field "S.a.b.c.d.e.f" and want to check whether it is empty or not, but are not sure whether all of its parent fields ("a.b.c.d.e") exist. We could use "isfield" on each of the parent fields, but this is quite a hassle and requires several lines of code. Instead we can simply call:

tf = isempty_field(S,'S.a.b.c.d.e.f');

The function will return false when the field "S.a.b.c.d.e.f" exists AND is not empty, and true otherwise.

Cite As

Terence Brouns (2026). isempty_field - Easily check whether a deeply nested field is empty or non-existent (https://www.mathworks.com/matlabcentral/fileexchange/67918-isempty_field-easily-check-whether-a-deeply-nested-field-is-empty-or-non-existent), MATLAB Central File Exchange. Retrieved .

Acknowledgements

Inspired by: Get structure field names in recursive manner

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0