How to find required inputs from Input Parser object?
4 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Argument Definitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!