How to use the "parse" function to create optional function inputs
古いコメントを表示
Hello,
I am trying to use "parse" to create optional function inputs. Tried to replicate examples in the documentation (see below and attached) but I get the "too many arguments" error. Any idea? Thanks
my code below:
----------------
function []=testFun(A,varargList)
p = inputParser;
defaultNorm = 'L2';
validNorms = {'L1','L2'};
checkNorm = @(x) any(validatestring(x,validNorms));
addOptional(p,'lambda',0,@isnumeric)
addOptional(p,'norm',defaultNorm,checkNorm)
parse(A,varargList{:})
lambda = p.Results.lambda;
norm = p.Results.norm;
disp('input1 = ')
disp(A)
disp('lambda = ')
disp(lambda)
disp('norm = ')
disp (norm)
end
採用された回答
その他の回答 (1 件)
Walter Roberson
2017 年 2 月 5 日
1 投票
The variable name has to be varargin to be recognized as special, not varargList
1 件のコメント
Francois Steiner
2017 年 2 月 6 日
編集済み: Francois Steiner
2017 年 2 月 6 日
カテゴリ
ヘルプ センター および File Exchange で Argument Definitions についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!