2014-02-13 152 views
1

我有一些麻煩,在創建MATLAB類和我真的不明白它背後的方法(我是相當新的吧) 這裏用我的基本除了嘗試MATLABMatlab的類基礎知識

classdef測試

性質

a 
    b  

方法

function add = plus(a, b) 
    end 

通過

p=test(), p.a=5 

等分配值似乎做工精細,但試圖p.add返回錯誤

No appropriate method, property, or field add for class test. 

任何幫助或指導將是appartiated,謝謝。

回答

2

方法的定義與函數名稱和輸出相同。

因此,該方法被稱爲plus,輸出的方法應計算被稱爲add,你可能想寫的方法的方法是:

function out = add(this) 
    out = this.a + this.b; 
end 

現在你罵的方法

p.add();