Can one use the argument block to check structures at arbitrary depth?

2 views (last 30 days)
For example, is the following legal:
arguments
analyzer (1,1) struct {mustContainFields(analyzer, ["P", "loops"])}
end
arguments (Input)
% Validate nested structures more specifically if needed,
% e.g., ensuring P.param and loops.conds exist and are cell arrays.
% This basic check ensures the top-level fields are present.
analyzer.P (1,1) struct {mustContainFields(analyzer.P, "param")}
analyzer.P.param (1,:) cell % ERROR HERE
analyzer.loops (1,1) struct {mustContainFields(analyzer.loops, "conds")}
analyzer.loops.conds (1,:) cell
end
I assume it's just not legal? That is, can one only validate one level deep? (Fields of structures, but not fields of structures that are fields of structures)
Thanks
Steve

Accepted Answer

Steve Van Hooser
Steve Van Hooser on 14 Apr 2025
Answering my own:
Apparently you cannot check the fields of a structure in an argument block. You can only do this if the structure is passed to the function as an input of name/value pairs. So all lines after the first are invalid.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Tags

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!