Why does inputparser instantiated within a class subfunction not use the default for the first optional argument?
Afficher commentaires plus anciens
Hi there,
When I create an inputparser within a class method with a nested subfunction, it appears to not instantiate the first optional argument to the default value.
With the following test class:
classdef testclass < handle
properties
a
b
c
d
e
f
end
methods
function t = testclass(varargin)
p = inputParser;
addOptional(p,'a',1);
addOptional(p,'b',2);
addOptional(p,'c',3);
addOptional(p,'d',4);
addOptional(p,'e',5);
addOptional(p,'f',6);
parse(p,varargin{:});
t.a = p.Results.a;
t.b = p.Results.b;
t.c = p.Results.c;
t.d = p.Results.d;
t.e = p.Results.e;
t.f = p.Results.f;
end
function testfun(t,varargin)
testsubfun(t,varargin)
function testsubfun(t,varargin)
p = inputParser;
addOptional(p,'a',1);
addOptional(p,'b',2);
addOptional(p,'c',3);
addOptional(p,'d',4);
addOptional(p,'e',5);
addOptional(p,'f',6);
parse(p,varargin{:});
p.Results
end
end
end
end
If you call:
t=testclass('b',13,'c',14)
testfun(t,'b',13,'d',84)
I would expect the p.Results field to include the default value for the property 'a.' Instead, the entire varargin list is used as the value for that parameter. Is this a bug, or am I doing something wrong?
Thanks,
Lucas
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Argument Definitions dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!