isempty_field - Easily check whether a deeply nested field is empty or non-existent
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
Platform Compatibility
Windows macOS LinuxCategories
Tags
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!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
fieldnamesr/
Version | Published | Release Notes | |
---|---|---|---|
1.0 |
|