How to Define a Default Input Argument for a Function?
2 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Adam
2017-3-1
编辑:Adam
2017-3-1
function someFunc( someInput )
narginchk( 0, 1 )
if ~exist( 'someInput', 'var' )
someInput = 7;
end
...
end
Generally I add an extra line something like the following, but I'm fussy:
if exist( 'someInput', 'var' )
validateattributes( someInput, { 'double' }, { 'scalar', 'nonnegative' } )
else
someInput = 7;
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!