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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Steve Van Hooser
Steve Van Hooser el 14 de Abr. de 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.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by