Effacer les filtres
Effacer les filtres

"Input parser" vs. new "arguments" definition

28 vues (au cours des 30 derniers jours)
Stefan Sp.
Stefan Sp. le 17 Jan 2022
Modifié(e) : Stephen23 le 26 Juin 2023
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 commentaire
chicken vector
chicken vector le 7 Avr 2023
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.

Connectez-vous pour commenter.

Réponses (1)

埃博拉酱
埃博拉酱 le 7 Avr 2023
Modifié(e) : 埃博拉酱 le 7 Avr 2023
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 commentaires
Simon
Simon le 26 Juin 2023
I have the same question. Both inputParser and arguments are unfamiliar to me.
Stephen23
Stephen23 le 26 Juin 2023
Modifié(e) : Stephen23 le 26 Juin 2023
@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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Argument Definitions dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by