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

 채택된 답변

Matt J
Matt J 2022년 3월 17일

1 개 추천

The validation function should be the 4th argument,
addParameter(p, 'property_name','', isString) ;

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Argument Definitions에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2022년 3월 17일

답변:

2022년 3월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by