arguments struct expand like inputParser

15 ビュー (過去 30 日間)
Paul Villain
Paul Villain 2022 年 10 月 30 日
回答済み: Paul Villain 2022 年 10 月 31 日
Hi to anybody who could enlighten me
Matlab's arguments synthax is excelent for function's input validation and allow for very usuefull tip to the end user when using the function. However I found myself wondering if argument would replace inputParser in the future. I find inputParser to be way more flexible than arguments and would greatly miss such a functionality if it would ever get removed.
Technical context: for inputParser type functions, it is always possible to pass a struct as input to a Name-Value pair argument
function myFun(varargin)
p=inputParser;
p.addParameter('a',defaultValue,validationFunction)
p.addParameter('b',defaultValue,validationFunction)
p.StructExpand=true; % true by default
end
could be called in two ways
myFun('a',myValueForA,'b',myValueForB)
or
s.a=myValueForA
s.b=myValueForB
myFun(s)
I am an avid user of the 2nd method and found myself in trouble when I tried using this sythax with the Name-Value structure of the arguments.
To repeat again the question: Is there a way to expand struct input to a function accepting Name-Value type using the arguments validation structure in the same maner as inputParser?
Thanks in advance for your answers

採用された回答

Paul Villain
Paul Villain 2022 年 10 月 31 日
found my luck
this is not possible
Answer hier see also possible workaround from Walter Roberson

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeArgument Definitions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by