How to partially validate arguments?
Afficher commentaires plus anciens
Rewriting some legacy code to arguments block style I run into cases where I should validate some arguments and pass the rest as is to other functions. This is about what I would like to accomplish:
function f1(positional, optional_positional, options, varargin)
arguments
positional;
optional_positional = 0;
% options validated by f1
options.f1_option = true;
end
arguments (Repeating)
% arguments without validation, to be validated by f2
varargin;
end
% Doing things with validated arguments goes here.
% Eventually passing the non-validated arguments to another function.
f2(varargin{:});
end
Above leads to an error:
Function argument definition error in f1. Functions with positional and name-value arguments must define positional arguments first.
So it would seem what I'm trying to do isn't exactly supported. Did I make a mistake somewhere? Is there another way of doing it?
Edit: What I'm after is very similar to inputParser KeppUnmatched option: Input parser for functions - MATLAB - MathWorks Nordic
Réponse acceptée
Plus de réponses (1)
Andreas Urbán
le 21 Mar 2022
Modifié(e) : Andreas Urbán
le 21 Mar 2022
Catégories
En savoir plus sur Function Creation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!