inputParser does not throw error

1 Ansicht (letzte 30 Tage)
Grzegorz Lippe
Grzegorz Lippe am 17 Mär. 2022
Beantwortet: Matt J am 17 Mär. 2022
I want to check, whether an input is a string. Why does it not work?
p = inputParser() ;
isString = @(x) (isvector(x) | isempty(x)) & ischar(x) ;
addParameter(p, 'property_name', isString) ;
isString(13) % yields False
parse(p, 'property_name', 13) % Throws no error

Akzeptierte Antwort

Matt J
Matt J am 17 Mär. 2022
The validation function should be the 4th argument,
addParameter(p, 'property_name','', isString) ;

Weitere Antworten (0)

Kategorien

Mehr zu Argument Definitions finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by