poster
2019-12-05, 23:04
这有效(画出“空”图):
function testme plot(1) 这有效(返回1):
function testme plot = @(x)x; plot(1) 这不是(错误:“未定义的函数或变量'图'。”):
function testme if 0 plot = @(x)x; end plot(1) 这里发生了什么?为什么重写但未重新定义已定义的函数会导致该函数未定义?
注1:这不是内置函数专用的;以下代码返回相同的错误:
function testme if 0 myfun = @(x)x; end myfun(1) function x=myfun(x) x=x*2; 注2:错误发生在函数环境中,而不是脚本中;以下代码不返回错误(并且绘制与第一个示例相同的空图):
if 0 plot = @(x)x; end plot(1)
更多&回答... (https://stackoverflow.com/q/59197724)
function testme plot(1) 这有效(返回1):
function testme plot = @(x)x; plot(1) 这不是(错误:“未定义的函数或变量'图'。”):
function testme if 0 plot = @(x)x; end plot(1) 这里发生了什么?为什么重写但未重新定义已定义的函数会导致该函数未定义?
注1:这不是内置函数专用的;以下代码返回相同的错误:
function testme if 0 myfun = @(x)x; end myfun(1) function x=myfun(x) x=x*2; 注2:错误发生在函数环境中,而不是脚本中;以下代码不返回错误(并且绘制与第一个示例相同的空图):
if 0 plot = @(x)x; end plot(1)
更多&回答... (https://stackoverflow.com/q/59197724)