Vous suivez désormais cette soumission
- Les mises à jour seront visibles dans votre flux de contenu suivi
- Selon vos préférences en matière de communication il est possible que vous receviez des e-mails
This simple helper-function lets you replace commonly seen input-argument handling code with shorter and clearer alternatives. For example, instead of:
if nargin < 2
x = 42;
end
if ~isfield(options, 'verbose')
options.verbose = false;
end
if ~isfield(options, 'method')
options.method = 1;
end
you can simply have:
default('x', 42)
default(options, 'verbose', false)
default(options, 'method', 1)
By avoiding nargin, you can more easily change function definitions without messing up all of the argument numbers, e.g. changing: function blah(input, verbose)
to: function blah(method, input, options, verbose)
only requires new default commands for method and options arguments, whereas use of nargin would need to change for input and verbose.
I find this useful -- I hope others do too! :-)
Citation pour cette source
Ged Ridgway (2026). Default arguments (https://fr.mathworks.com/matlabcentral/fileexchange/26111-default-arguments), MATLAB Central File Exchange. Extrait(e) le .
Informations générales
- Version 1.0.0.0 (2,64 ko)
Compatibilité avec les versions de MATLAB
- Compatible avec toutes les versions
Plateformes compatibles
- Windows
- macOS
- Linux
| Version | Publié le | Notes de version | Action |
|---|---|---|---|
| 1.0.0.0 |
