How to Define a Default Input Argument for a Function?

1 ビュー (過去 30 日間)
Rightia Rollmann
Rightia Rollmann 2017 年 3 月 1 日
編集済み: Adam 2017 年 3 月 1 日
How to define a default input argument for a function? I want to set a default input argument which will be replaced later by new values entered by user. How?


Adam 2017 年 3 月 1 日
編集済み: Adam 2017 年 3 月 1 日
function someFunc( someInput )
narginchk( 0, 1 )
if ~exist( 'someInput', 'var' )
someInput = 7;
Generally I add an extra line something like the following, but I'm fussy:
if exist( 'someInput', 'var' )
validateattributes( someInput, { 'double' }, { 'scalar', 'nonnegative' } )
someInput = 7;

その他の回答 (0 件)


Find more on Argument Definitions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by