How to find required inputs from Input Parser object?
Mostra commenti meno recenti
Hi Community,
I am have implemented 'InputParser' for my MATLAB function. Here's the code snippet-
function fitElliOntoDatam_10_edit(filen,NrPlanes,makePlots)
defaultMakePlot = false;
%%%%%%% INPUT PARSER %%%%%%%%
p = inputParser;
p.FunctionName = 'fitElliOntoDatam_10_edit';
validNum = @(x) isnumeric(x) && (x > 0);
addRequired(p,'filen',@isstring);
addRequired(p,'NrPlanes',validNum);
addOptional(p,'makePlots',defaultMakePlot,@islogical);
parse(p,filen,NrPlanes,makePlots);
disp(p);
.....
......
So, when I print the inputParser object, I get the following detail -
>> fitElliOntoDatam_10_edit("export.txt",20,false)
inputParser with properties:
FunctionName: 'fitElliOntoDatam_10_edit'
CaseSensitive: 0
KeepUnmatched: 0
PartialMatching: 1
StructExpand: 1
Parameters: {'filen' 'makePlots' 'NrPlanes'}
Results: [1×1 struct]
Unmatched: [1×1 struct]
UsingDefaults: {1×0 cell}
How can I display which of these 3 parameters are 'required' or 'optional'? Where is that information stored inside inputParser object?
Also can I display the data type of these parameters from the inputParser object? Where do the validation functions get stored ?
5 Commenti
Steven Lord
il 9 Dic 2022
I'm not sure that information is available from the inputParser object. Can you share more information about how you're hoping to use that information, what you would do with it if it was available? There may be alternate ways to accomplish your goal using different functions.
Atin
il 9 Dic 2022
Steven Lord
il 9 Dic 2022
How do you intend or hope to use that XML file?
We have the capability to obtain class metadata but I don't believe there's an equivalent for functions.
If you had written or can write a functionSignatures.json file to customize suggestions and completions for your functions, parsing that JSON file might be an easier approach for gathering some of the data you're looking for.
Atin
il 12 Dic 2022
Risposte (0)
Categorie
Scopri di più su Argument Definitions in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!