keep live-function (member?) help from repeating options?

5 visualizzazioni (ultimi 30 giorni)
Is there a way to avoid repeated help/doc options?
I see help/doc syntax like this for a live function member (in its own file):
x = myFun(this, options, options, options)
versus syntax like this for an ordinary function member (ditto):
x = myFun(this, options)
for an arguments block like this:
arguments
this { mustBeNonmissing }
options.A (1,1) double = 1.0;
options.B double = 0;
options.C (1,1) boolean = false;
end

Risposte (1)

Rishav
Rishav il 5 Set 2023
Modificato: Rishav il 5 Set 2023
Hi T. David,
Instead of using 'options', you can use 'inputParser' class in MATLAB to handle the input arguments in a more flexible manner.
Here's an example of how you can modify your code:
function x = func(this,varargin)
% Create a parser object
parser = inputParser;
% Define the compulsory parameter 'this'
addRequired(parser,'this',@mustBeNonmissing);
% Define the input parameters
addParameter(parser, 'A', 1.0, @isnumeric);
addParameter(parser, 'B', 0, @isnumeric);
addParameter(parser, 'C', false, @islogical);
% Parse the input arguments
parse(parser, this, varargin{:});
% Access the values
thisValue = parser.Results.this;
optionA = parser.Results.A;
optionB = parser.Results.B;
optionC = parser.Results.C;
end
By using the 'inputParser' class, you can define compulsory parameters (e.g., 'this') and optional parameters ('A', 'B', 'C') with their default values and validation functions.
'varargin' allows you to pass multiple parameters to the function, making it more flexible and avoiding the use of 'options' argument.

Categorie

Scopri di più su Argument Definitions in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by