nargin-----输入参数个数判断------matlab
2010-01-04 10:53
1036 查看
nargin, nargout
Number of function
arguments
Syntax
nargin
nargin(fun)
nargout
nargout(fun)
Description
In the body of a function M-file, nargin and nargout
indicate how many input or output arguments, respectively, a user has supplied.
Outside the body of a function M-file, nargin and nargout indicate the number of
input or output arguments, respectively, for a given function. The number of
arguments is negative if the function has a variable number of arguments.
nargin returns the number of input arguments specified for a
function.
nargin(fun) returns the number of declared inputs for the
function fun. If the function has a variable number of input arguments, nargin
returns a negative value. fun may be the name of a function, or the name of
Function Handles that map to specific functions.
nargout returns the number of output arguments specified for
a function.
nargout(fun) returns the number of declared outputs for the
function fun. fun may be the name of a function, or the name of Function Handles
that map to specific functions.
Examples
This example shows portions of the code for a function
called myplot, which accepts an optional number of input and output
arguments:
function [x0,
y0] = myplot(x, y, npts, angle, subdiv)
% MYPLOT Plot a
function.
% MYPLOT(x, y, npts, angle, subdiv)
% The first two input arguments are
% required; the other three have default values.
...
if nargin < 5, subdiv = 20; end
if nargin < 4, angle = 10; end
if nargin
< 3, npts = 25; end
...
if nargout
== 0
plot(x, y)
else
x0 = x;
y0 = y;
end
Number of function
arguments
Syntax
nargin
nargin(fun)
nargout
nargout(fun)
Description
In the body of a function M-file, nargin and nargout
indicate how many input or output arguments, respectively, a user has supplied.
Outside the body of a function M-file, nargin and nargout indicate the number of
input or output arguments, respectively, for a given function. The number of
arguments is negative if the function has a variable number of arguments.
nargin returns the number of input arguments specified for a
function.
nargin(fun) returns the number of declared inputs for the
function fun. If the function has a variable number of input arguments, nargin
returns a negative value. fun may be the name of a function, or the name of
Function Handles that map to specific functions.
nargout returns the number of output arguments specified for
a function.
nargout(fun) returns the number of declared outputs for the
function fun. fun may be the name of a function, or the name of Function Handles
that map to specific functions.
Examples
This example shows portions of the code for a function
called myplot, which accepts an optional number of input and output
arguments:
function [x0,
y0] = myplot(x, y, npts, angle, subdiv)
% MYPLOT Plot a
function.
% MYPLOT(x, y, npts, angle, subdiv)
% The first two input arguments are
% required; the other three have default values.
...
if nargin < 5, subdiv = 20; end
if nargin < 4, angle = 10; end
if nargin
< 3, npts = 25; end
...
if nargout
== 0
plot(x, y)
else
x0 = x;
y0 = y;
end
相关文章推荐
- python 函数判断输入参数个数 类似 matlab nargin
- MATLAB中nargin函数的用法nargin是用来判断输入变量个数的函数,这样就可以针对不同的情况执行不同的功能。通常可以用它来设定一些默认值。如下例所示: 函数文件 examp.m
- (三)、利用命令行参数输入多个参数,判断该数组是否为回文数组
- 每日总结(二)C#判断输入内容为数字、Sharepoint回收应用程序池错误、Asp.Net 会发或回调参数无效、DropDownList动态绑定且设置默认选择项
- linux 判断输入参数个数
- linux shell中判断bash脚本输入的参数个数
- 对于 输入框为空及输入参数只有空格的判断 ios
- 如何判断在shell程序命令行输入的程序参数$1是否为空 (2010-08-04 16:37:56)
- matlab获取函数参数数目nargout与nargin
- Shell脚本中判断输入参数个数的方法
- shell判断输入的参数是不是数字
- 每日总结(二)C#判断输入内容为数字、Sharepoint回收应用程序池错误、Asp.Net 会发或回调参数无效、DropDownList动态绑定且设置默认选择项
- Shell脚本中判断输入参数个数的方法投稿:junjie 字体:[增加 减小] 类型:转载
- Perl脚本学习经验(一)------如何判断执行脚本时的输入参数是否正确
- Shell脚本中判断输入变量或者参数是否为空的方法
- shell判断输入的参数是不是数字
- 函数对非法参数输入的判断需要做到什么程度?
- 在命令行输入参数 判断每个参数输入的次数
- 初学Matlab:自定义函数中给定输入参数的默认值
- MATLAB函数的输入参数传递方式探秘