Error when using validatestring in inputParser addOptional
古いコメントを表示
I'm getting the following error when running isenExpan('a','m',2,1.4,'sub') with the code below:
??? Error using ==> isenExpan
Argument 'sonic' failed validation
@(x)validatestring(x,validSonic).
code:
function out = isenExpan(from,to,val,gam,varargin)
%%error checking
validTypes = {'m', 'a', 'p', 't', 'd'};
validSonic = {'super', 'sub'};
p = inputParser;
p.FunctionName = 'isenExpan';
p.addRequired('from', @(x)validatestring(x,validTypes));
p.addRequired('to', @(x)validatestring(x,validTypes));
p.addRequired('val', @isnumeric);
p.addRequired('gam', @(x)validateattributes(x,{'numeric'},{'>',1,'<',1.5}));
p.addOptional('sonic', 'super', @(x)validatestring(x,validSonic));
p.parse(from,to,val,gam,varargin{:});
I'm giving sonic a valid input, and when I step through itin debug mode, validatestring returns 'sub' and not false.
Has anyone else seen or heard of this problem?
1 件のコメント
David Ternet
2013 年 8 月 12 日
Another question related to this. Is anyone else frustrated by the way many of these APIs rely on exceptions or text display results? For example, why couldn't validatestring (or inputparser.parse) return a simple true/false instead of using an exception to indicate failure? It seems a bit costly to add try/catch blocks around many of these API calls just to find out if something was successful or not.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Argument Definitions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!