【问题标题】:What does at @ mean in MATLAB when creating an instance of a class?创建类的实例时,@ 在 MATLAB 中是什么意思?
【发布时间】:2016-12-12 17:33:41
【问题描述】:

例如:

function s = slexpdatasetSLAP()
    s = s@slexpdataset('slapCC','SLAP dataset for collective classification'); %slexpdataset is a class defined in another .m file
    s.discription ='CC';
end

据我所知,@ 被用作在 MATLAB 中创建函数句柄,但显然这种解释不适合这种情况。那么@ 是什么意思?

【问题讨论】:

    标签: matlab oop


    【解决方案1】:

    这是调用the constructor of the super-class的语法

    一般来说,for calling a method of the superclass,你会使用语法

    outputs = methodName@superclassname(obj, input, arguments)
    

    但是,调用构造函数有点不同,因为您使用对象实例的变量名代替上面示例中的methodName

    obj = obj@superclassname(input, arguments)
    

    在您的情况下,您使用s 作为引用类实例的变量而不是obj(因为您将其定义为构造函数的输出),所以您实际上是在调用构造函数slexpdataset 并将显示的参数列表传递给它。

    【讨论】:

      猜你喜欢
      • 2020-01-09
      • 2017-10-21
      • 1970-01-01
      • 2017-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-07
      • 1970-01-01
      相关资源
      最近更新 更多