function函数嵌套 matlab_matlab – 当没有使用“end”时,一个.m文件中的多个函数是嵌套的还是本地的...

在MATLAB中,您可以在一个.m文件中拥有多个函数.当然有主要功能,然后是

nested or local functions.

每种功能类型的示例:

% myfunc.m with local function ------------------------------------------

function myfunc()

disp(mylocalfunc());

end

function output = mylocalfunc()

% local function, no visibility of variables local to myfunc()

output = 'hello world';

end

% -----------------------------------------------------------------------

% myfunc.m with nested function -----------------------------------------

function myfunc()

disp(mynestedfunc());

function output = mynestedfunc()

% nested function, has visibility of variables local to myfunc()

output = 'hello world';

end

end

% ----------------------------------------------------------------------

使用函数的结束语句时,差异很明显.但是,我不认为你没有清楚地记录你使用的是什么,因为这是有效的语法:

% myfunc.m with some other function

function myfunc()

disp(myotherfunc());

function output = myotherfunc()

% It's not immediately clear whether this is nested or local!

output = 'hello world';

有没有明确定义像myotherfunc这样的函数是本地函数还是嵌套函数?

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值