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

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Steve Van Hooser
Steve Van Hooser am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by