MATLAB中函数function是怎么用的?
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/09/22 12:35:11
MATLAB中函数function是怎么用的?
输入:
help function
就会出现帮助!
FUNCTION Add new function.
New functions may be added to MATLAB's vocabulary if they
are expressed in terms of other existing functions.The
commands and functions that comprise the new function must
be put in a file whose name defines the name of the new
function,with a filename extension of '.m'.At the top of
the file must be a line that contains the syntax definition
for the new function.For example,the existence of a file
on disk called STAT.M with:
function [mean,stdev] = stat(x)
%STAT Interesting statistics.
n = length(x);
mean = sum(x) / n;
stdev = sqrt(sum((x - mean).^2)/n);
defines a new function called STAT that calculates the
mean and standard deviation of a vector.The variables
within the body of the function are all local variables.
See SCRIPT for procedures that work globally on the work-
space.
A subfunction that is visible to the other functions in the
same file is created by defining a new function with the FUNCTION
keyword after the body of the preceding function or subfunction.
For example,avg is a subfunction within the file STAT.M:
function [mean,stdev] = stat(x)
%STAT Interesting statistics.
n = length(x);
mean = avg(x,n);
stdev = sqrt(sum((x-avg(x,n)).^2)/n);
%-------------------------
function mean = avg(x,n)
%AVG subfunction
mean = sum(x)/n;
Subfunctions are not visible outside the file where they are defined.
Normally functions return when the end of the function is reached.
A RETURN statement can be used to force an early return.
See also script,return,varargin,varargout,nargin,nargout,
inputname,mfilename.
Reference page in Help browser
doc function
help function
就会出现帮助!
FUNCTION Add new function.
New functions may be added to MATLAB's vocabulary if they
are expressed in terms of other existing functions.The
commands and functions that comprise the new function must
be put in a file whose name defines the name of the new
function,with a filename extension of '.m'.At the top of
the file must be a line that contains the syntax definition
for the new function.For example,the existence of a file
on disk called STAT.M with:
function [mean,stdev] = stat(x)
%STAT Interesting statistics.
n = length(x);
mean = sum(x) / n;
stdev = sqrt(sum((x - mean).^2)/n);
defines a new function called STAT that calculates the
mean and standard deviation of a vector.The variables
within the body of the function are all local variables.
See SCRIPT for procedures that work globally on the work-
space.
A subfunction that is visible to the other functions in the
same file is created by defining a new function with the FUNCTION
keyword after the body of the preceding function or subfunction.
For example,avg is a subfunction within the file STAT.M:
function [mean,stdev] = stat(x)
%STAT Interesting statistics.
n = length(x);
mean = avg(x,n);
stdev = sqrt(sum((x-avg(x,n)).^2)/n);
%-------------------------
function mean = avg(x,n)
%AVG subfunction
mean = sum(x)/n;
Subfunctions are not visible outside the file where they are defined.
Normally functions return when the end of the function is reached.
A RETURN statement can be used to force an early return.
See also script,return,varargin,varargout,nargin,nargout,
inputname,mfilename.
Reference page in Help browser
doc function
MATLAB中函数function是怎么用的?
matlab中function 函数怎么用?
matlab,中,一个函数f=x^2+1,怎么表示,是函数,function定义的函数
function在MATLAB中怎么用
matlab中 function怎么用啊?
MATLAB用function定义一个函数后 怎么让这个函数生效 是把这个M文件存到哪啊
function 在matlab中怎么定义矩阵
matlab用input让用户输入一函数f(x)后,怎么把他变成matlab里面的function自定义函数
关于matlab中function的问题!
matlab里面的function的输入参数有函数怎么调用?
如何在matlab中运行一下function函数
matlab中function定义函数,出现自变量未定义错误,是怎么回事?