0

I'd like to change my class properties with a method defined for that class:

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

Calling:

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

It's not working at all - I get this error:

 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()

I'm using matlab 2012a. My code is based on this example: link

Community
  • 1
  • 1
Arxas
  • 241
  • 2
  • 4
  • 13

1 Answers1

2

Try clear before doing this. It is possible that you've overwritten handle with something. Otherwise, this works for me on Matlab 2012a:

clear;

a = 'hello';
h = 1;

t = triangle();
t.setProps(a, h);
Barney Szabolcs
  • 11,846
  • 12
  • 66
  • 91