How do I use the inputParser to validate my required input is a string from a defined set of acceptable strings?
Mostra commenti meno recenti
I am having trouble with my function parsing a required string input. I want it to validate the input is an acceptable string. Code with subsequent error as a comment:
p = inputParser;
argName = 'monkey';
monkeys = [ "toejam","earl" ];
validationFcn = @(x) any(validatestring(x,monkeys));
addRequired(p,argName,validationFcn);
parse(p,"toejam")
% The value of 'monkey' is invalid. Invalid data type. First argument must be numeric or logical.
Why is it looking for a numeric input when I have the validation function defined using strings?
Thank you in advance for any help.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Argument Definitions in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!