zoukankan      html  css  js  c++  java
  • nargin

    nargin, nargout


    Number of function arguments
    Syntax

    nargin
    nargin(fun)
    nargout
    nargout(fun)

    Description


    In the body of a function, nargin and nargout indicate how many input or output arguments, respectively, a user has supplied. Outside the body of a function, 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. If the function has a variable number of output arguments, nargout returns a negative value. 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

    See Also

    inputname, varargin, varargout, nargchk, nargoutchk
  • 相关阅读:
    HDU4507 吉哥系列故事――恨7不成妻(数位dp)
    UCF Local Programming Contest 2017 G题(dp)
    ICPC Latin American Regional Contests 2019 I题
    UCF Local Programming Contest 2017 H题(区间dp)
    HDU2089 不要62
    AcWing1084 数字游戏II(数位dp)
    UCF Local Programming Contest 2017 F题(最短路)
    Google Code Jam 2019 Round 1A Pylons(爆搜+贪心)
    AcWing1083 Windy数(数位dp)
    Vue
  • 原文地址:https://www.cnblogs.com/wangshixi12/p/4506039.html
Copyright © 2011-2022 走看看