In the following function, I tried to let Pt be on optional input parameter. In case Pt is not specified, it needs other optional parameters to be computed (that part works). But when I specify it:
Alg(b,'circle','Pt',ones(150,1))
I get the following error:
'Pt' is not a recognized parameter. For a list of valid name-value pair arguments, see the documentation for this function.
Code of the function:
function [ v ] = Alg( b,shape,varargin )
%%Parse inputs
p = inputParser;
addRequired(p,'b',@isnumeric);
expectedShapes = {'square','circle'};
addRequired(p,'shape',@(x) any(validatestring(x,expectedShapes)));
defaultIt = 42;
addParameter(p,'It',defaultIter,@isnumeric);
addParameter(p,'t',@isnumeric);
addParameter(p,'v',@isnumeric);
parse(p,b,shape,varargin{:})
b = p.Results.b;
shape = p.Results.shape;
It = p.Results.It;
t = p.Results.t;
v = p.Results.v;
parse(p,b,shape,varargin{:})
defaultPoint = Alg_sq(b,Pt,It);
defaultPoint = Sub_Alg(defaultPoint,shape,t,v);
addParameter(p,'Pt',defaultPoint,@isnumeric);
Pt = p.Results.Pt;
%%Shape
switch shape
case 'circle'
v = Alg_crcl( b,Pt,It );
case 'square'
v = Alg_sq( b,Pt,It );
end
end
Thanks a lot for your help!