varargin error for optional inputs
I was running this code
%%Parse Inputs
p = inputParser;
p.FunctionName = ‘linear_inversion_ksn’;
% required inputs
addRequired(p,’DEM’, @(x) isa(x,’GRIDobj’));
% optional inputs
addOptional(p,’crita’, 1e6, @(x) isscalar(x));
addOptional(p,’mn’, 0.5, @(x) isscalar(x));
addOptional(p,’chi_inc’, 1, @(x) isscalar(x));
addOptional(p,’gam’, 10, @(x) isscalar(x));
addOptional(p,’flowOption’, []);
parse(p,DEM, varargin{:});
DEM = p.Results.DEM;
And got an error like this
>> parse(p,DEM, varargin{:});
Brace indexing into the result of a function call is not supported. Assign the result
of ‘varargin’ to a variable first, then brace index into it.
Kindly help me in fixing itI was running this code
%%Parse Inputs
p = inputParser;
p.FunctionName = ‘linear_inversion_ksn’;
% required inputs
addRequired(p,’DEM’, @(x) isa(x,’GRIDobj’));
% optional inputs
addOptional(p,’crita’, 1e6, @(x) isscalar(x));
addOptional(p,’mn’, 0.5, @(x) isscalar(x));
addOptional(p,’chi_inc’, 1, @(x) isscalar(x));
addOptional(p,’gam’, 10, @(x) isscalar(x));
addOptional(p,’flowOption’, []);
parse(p,DEM, varargin{:});
DEM = p.Results.DEM;
And got an error like this
>> parse(p,DEM, varargin{:});
Brace indexing into the result of a function call is not supported. Assign the result
of ‘varargin’ to a variable first, then brace index into it.
Kindly help me in fixing it I was running this code
%%Parse Inputs
p = inputParser;
p.FunctionName = ‘linear_inversion_ksn’;
% required inputs
addRequired(p,’DEM’, @(x) isa(x,’GRIDobj’));
% optional inputs
addOptional(p,’crita’, 1e6, @(x) isscalar(x));
addOptional(p,’mn’, 0.5, @(x) isscalar(x));
addOptional(p,’chi_inc’, 1, @(x) isscalar(x));
addOptional(p,’gam’, 10, @(x) isscalar(x));
addOptional(p,’flowOption’, []);
parse(p,DEM, varargin{:});
DEM = p.Results.DEM;
And got an error like this
>> parse(p,DEM, varargin{:});
Brace indexing into the result of a function call is not supported. Assign the result
of ‘varargin’ to a variable first, then brace index into it.
Kindly help me in fixing it varargin, function MATLAB Answers — New Questions