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
43 Downloads
Updated 3 Jul 2018

View License

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 (2024). 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 .

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Structures in Help Center and MATLAB Answers
Acknowledgements

Inspired by: Get structure field names in recursive manner

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0