2012-12-01 69 views
0

我想和這個類中定義的方法來改變我的類屬性:它的方法改變類屬性

classdef triangle<handle 

properties 
    a 
    h   
end 

methods 

    function obj = triangle() 
     obj; 
    end 

    function obj = setProps(obj, a, h) 
     obj.a = a; 
     obj.a = h; 
    end 

end 

end 

呼叫:

t = triangle(); 
t.setProps(a, h); 

它不工作 - 我得到此錯誤:

The class 'handle' is not a super-class of class 'triangle', as required to invoke a super-class constructor or method. 

Error in triangle (line 13) 
    function obj = triangle() 

我正在使用matlab 2012a。我的代碼是基於此示例:link

回答

2

嘗試clear之前這樣做。有可能你用某種東西覆蓋了handle。否則,這適用於我在Matlab 2012a上:

clear; 

a = 'hello'; 
h = 1; 

t = triangle(); 
t.setProps(a, h); 
+0

清除幫助,感謝您的建議:) – Arxas