defaults.m

Version 1.0.0.0 (1.92 KB) by jl
Utility function to simplify setting default values for variables in functions.
308 Downloads
Updated 30 Jul 2014

View License

Syntax:
DEFAULTS('Variable',Value)

Problem:
Usually in a function call:
out = function(Var1, Var2)

if (~exist('Var1','var')
Var1 = 1234;
end
if (~exist('Var2','var')
Var2 = 3456;
end

This gets tedious after a while.

Solution using DEFAULTS
out = function(Var1, Var2)
defaults('Var1',1234,'Var2',3456);

Cite As

jl (2024). defaults.m (https://www.mathworks.com/matlabcentral/fileexchange/47394-defaults-m), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Argument Definitions in Help Center and MATLAB Answers
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0