Main Content

iptchecknargin

Check number of input arguments

iptchecknargin will be removed in a future release. Use narginchk instead.

Description

example

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

collapse all

Create a function called test_function that accepts any number of input arguments. Within the function, call iptchecknargin to check that the number of arguments passed to the function is within the range [1, 3]. Save the function with the file name test_function.m.

function test_function(varargin)
    iptchecknargin(1,3,nargin,mfilename);
end

Trigger the error message by executing the function at the MATLAB® command line, specifying more than the expected number of arguments.

test_function(eye(3),5,pi,7)

Input Arguments

collapse all

Smallest valid number of input arguments, specified as a nonnegative integer.

Largest valid number of input arguments, specified as a nonnegative integer or Inf.

Number of actual input arguments, specified as a nonnegative integer. You can also specify nargin to use the number of function input arguments to the currently executing function.

Function name to include in an error message when num_inputs is an invalid number of input arguments, specified as a character vector or string scalar. You can also specify mfilename to use the name of the currently executing function.

Data Types: char | string

Version History

Introduced before R2006a