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