【发布时间】:2015-11-04 01:12:19
【问题描述】:
如果我有一个带有
的 MATLAB 类 MyClassclassdef MyClass
properties
myArray
end
methods
function update(obj, i)
obj.myArray[i] = i*5;
end
end
我用
调用更新函数myClass.update(i)
myArray 对象在 i 递增时不会“记住”更新,并且我得到一个空属性。 IE。我的数组 = []
但是,如果我将函数定义如下
classdef MyClass
properties
myArray
end
methods
function out = update(obj, i)
out = i*5;
end
end
并调用更新函数
myClass.myArray[i] = update(i)
会记住对 myArray 属性的更新。 IE。 IE。 myArray = [5, 10, 15, 20, 25]
那么这里发生了什么?...在所有其他语言中,这将按预期工作,似乎这里有一些 MATLAB 特定的奇怪范围/引用。有人知道发生了什么吗?
【问题讨论】:
-
您在此处粘贴的代码存在语法错误。
标签: matlab