asserts.hasField
Check that a structure has a field.
📝Syntax
asserts.hasField(s, fieldName)
[res, msg] = asserts.hasField(s, fieldName)
📥Input Arguments
Parameter Description
s Structure value.
fieldName Expected field name as a character vector or string scalar.
📤Output Arguments
Parameter Description
res true if the assertion passes, false otherwise.
msg assertion failure message, empty on success.
📄Description

The assertion passes when s contains fieldName.

Invalid non-structure inputs raise an argument error immediately.

💡Examples
Existing field
S = struct('a', 1); asserts.hasField(S, 'a');
Capture a missing field
S = struct('a', 1); [res, msg] = asserts.hasField(S, 'b');
🔗See Also
asserts.hasFieldsasserts.fields
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub