matlab中function函数的具体用法

来源:百度知道 编辑:UC知道 时间:2024/05/15 15:11:04
如题,在线等

1.新建一个m文件,把function函数复制进去;然后保存(名称应该是自动生成的,即为sinh.m,不过最好不要用和系统中的文件一样的名称,可以先help查看一下matlab是否有和sinh重复的名称,若有的话,得把function函数改个名称),保存的地址为当前工作目录。

2.在命令窗口调用function函数:

sinh(5)

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