了解MATLAB类属性(Understanding MATLAB class properties)
从MATLAB帮助中考虑这个例子 。
这个例子除了有语法问题外,并不适用于我。 我不知道是否是版本问题,我正在使用R2013a。
classdef MyClass
properties (Constant = true)
X = pi/180;
end
properties
PropA = sin(X*MyClass.getAngle([1 0],[0 1]);
end
methods (Static = true)
function r = getAngle(vx,vy)
end
end
end
它说
未定义的函数或变量'X'。 MyClass(第1行)中的错误classdef MyClass
我可以通过添加MyClass.X来修复它,但我不知道这是否是目的。
Considering this example from the MATLAB Help.
This example, besides having syntax problems, does not seams to work for me. I don't know if is a version issue, I'm using R2013a.
classdef MyClass
properties (Constant = true)
X = pi/180;
end
properties
PropA = sin(X*MyClass.getAngle([1 0],[0 1]);
end
methods (Static = true)
function r = getAngle(vx,vy)
end
end
end
It says
Undefined function or variable 'X'. Error in MyClass (line 1) classdef MyClass
I can fix it by adding MyClass.X, but I don't know if this was the purpose.
原文:https://stackoverflow.com/questions/22057351
2020-07-10 21:07
满意答案
MathWorks的例子都搞砸了。 意图可能是这样写的:
classdef MyClass
properties (Constant = true)
Deg2Rad = pi/180;
end
properties
PropA = sin(MyClass.Deg2Rad*MyClass.getAngle([1 0],[0 1]));
end
methods (Static = true)
function r = getAngle(vx,vy)
r = atan2(vy,vx)/MyClass.Deg2Rad;
end
end
end
我想重点是演示一个静态方法和