【发布时间】:2016-05-17 20:22:57
【问题描述】:
classdef hello < handle
methods
function first(obj)
a=4;
function second(obj)
a
end
end
end
end
我希望能够调用函数“obj.second”。
这是我尝试过的:
>> hello_obj=hello;
>> hello_obj.first
>> hello_obj.second
No appropriate method, property, or field second for class hello.
>> hello_obj.first.second
Attempt to reference field of non-structure array.
>> hello_obj.first.hello_obj.second
Attempt to reference field of non-structure array.
谢谢
【问题讨论】:
-
这不可能,你为什么认为你必须这样做?
-
我想利用嵌套函数可以访问其父函数的工作区这一事实(我不希望“a”成为属性)。
-
a在您尝试调用second时不再存在。我认为房产是最好的解决方案,但你可以解释你不使用房产的原因。这可能会带来更好的解决方案。 -
出于一个非常实际的原因:正如它所写的那样,在执行结束时,我的代码会保存工作区(包括对象),我不希望像这样的“工作”变量已保存。