matlab中的 variable,谁知道matlab中的问题Missing variable or function?

9cfb1158e458b8b4886a0d7cfd8759b4.png

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)

%MEAN 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.

◆◆

评论读取中....

请登录后再发表评论!

◆◆

修改失败,请稍后尝试

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值