www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/AddOptionalParameterValueInputExample.m
%% Add Optional Parameter Value Input % Create an |inputParser| object and add an optional input named |myparam| % with a default value of |0| to the input scheme. % Copyright 2015 The MathWorks, Inc. %% p = inputParser; paramName = 'myparam'; default = 0; addParameter(p,paramName,default); %% % Unlike the positional inputs added with the |addRequired| and |addOptional| % methods, each parameter added with |addParameter| corresponds to two input % arguments: one for the name and one for the value of the parameter. %% % Pass both the parameter name and value to the |parse| method. parse(p,'myparam',100); p.Results