2

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.

4

1 回答 1

5

那个 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

我想重点是演示一个静态方法和常量属性:

>> MyClass.getAngle(1,sqrt(3))
ans =
   60.0000
>> MyClass.getAngle(sqrt(3),1)
ans =
   30.0000
>> MyClass.getAngle(0,1)
ans =
    90
于 2014-02-27T01:55:28.987 回答