函数iptchecknargin()用于检查函数输入参数的个数。
执行函数主体代码前,先检查函数的输入参数个数是否满足要求。
ipt是image process tools,即图像处理工具的缩写,MALAB里边有一个图像像处理工具箱,里边有一组函数的命名规则是在前面加上ipt。
nargin是输入参数个数的意思,是number of arguments input的缩写。
在MATLAB的HELP中打开Product Help,然后搜索iptchecknargin,对这个函数的介绍如下:
iptchecknargin(low,high,num_inputs,func_name) checks whether num_inputs is a valid number of input arguments and issues a formatted error message if the number of input arguments is invalid.
If the number of input arguments is in the range [low high], then iptchecknargin returns nothing.
If the number of input argument is less than low or greater than high, then iptchecknargin issues a formatted error message that includes information about the function name (func_name). This value is used only to create the error message, not to check whether the number of input arguments is valid.
Examples
function test_function(varargin)
iptchecknargin(1,3,nargin,mfilename);
end
这里再搜索nargin,解释如下:
Nargin
Number of function arguments
Syntax
nargin
nargin(fun)
Description
In the body of a function, nargin indicates how many input arguments a user has supplied. ..........
以上英文介绍就不翻译了。