matlab中如何定义一个没有固定输入变量的函数
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/29 15:31:11
matlab中如何定义一个没有固定输入变量的函数
matlab中如何定义一个没有固定输入变量的函数
matlab中如何定义一个没有固定输入变量的函数
>> help varargin
VARARGIN Variable length input argument list.
Allows any number of arguments to a function. The variable
VARARGIN is a cell array containing the optional arguments to the
function. VARARGIN must be declared as the last input argument
and collects all the inputs from that point onwards. In the
declaration, VARARGIN must be lowercase (i.e., varargin).
For example, the function,
function myplot(x,varargin)
plot(x,varargin{:})
collects all the inputs starting with the second input into the
variable "varargin". MYPLOT uses the comma-separated list syntax
varargin{:} to pass the optional parameters to plot. The call,
myplot(sin(0:.1:1),'color',[.5 .7 .3],'linestyle',':')
results in varargin being a 1-by-4 cell array containing the
values 'color', [.5 .7 .3], 'linestyle', and ':'.
See also varargout, nargin, nargout, inputname, function, lists, paren.
Reference page in Help browser
doc varargin