How to find required inputs from Input Parser object?
古いコメントを表示
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 件のコメント
Steven Lord
2022 年 12 月 9 日
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
2022 年 12 月 9 日
Steven Lord
2022 年 12 月 9 日
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
2022 年 12 月 12 日
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Argument Definitions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!