"Input parser" vs. new "arguments" definition
조회 수: 21 (최근 30일)
표시 이전 댓글
R2019b introduced the new "arguments" section for function argument checking and parsing.
I hahe written some functions using the "old" input parser class. Are there any advantages to switch to the new syntax?
Is it worth to update my functions to the new syntax? (sure, I know, "never change a running system")
regards, Stefan
댓글 수: 1
chicken vector
2023년 4월 7일
Hi Stefan, this is a question of great interest.
Have you figured out an answer yet? I am implementing a library and I can't choose what to use.
답변 (1개)
埃博拉酱
2023년 4월 7일
편집: 埃博拉酱
님. 2023년 4월 7일
The biggest advantage of the arguments block is readability, but it is far less flexible than varargin. People who are not familiar with your code can quickly understand your parameter requirements through the arguments block.
Another potential advantage may be ease of compiler optimization. Overly flexible varargin is difficult to optimize for performance.
댓글 수: 4
Stephen23
2023년 6월 26일
편집: Stephen23
님. 2023년 6월 26일
@chicken vector: you can always use a comma-separated list, which works on every MATLAB version**:
options = {"parameters1", 1, "parameter2", 'foo', "parameter3", true}
myfunction(requiredInput, options{:})
** with cell arrays. AFAIK comma-separated lists were introduced at the same time.
참고 항목
카테고리
Help Center 및 File Exchange에서 Argument Definitions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!