matlab properties,了解MATLAB类属性(Understanding MATLAB class properties)

了解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

我想重点是演示一个静态方法和

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值