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

3 次查看(过去 30 天)
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

采纳的回答

Steve Van Hooser
Steve Van Hooser 2025-4-14
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by