help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling a method of an object?


From: Joanna Rutkowska
Subject: Re: Calling a method of an object?
Date: Thu, 18 Oct 2012 21:15:39 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120911 Thunderbird/15.0.1

On 10/18/12 21:00, Hoeltgen Laurent wrote:


2012/10/18 Joanna Rutkowska <address@hidden <mailto:address@hidden>>

    Hello, I've created a simple class:

    function m = motor (name, Kv, Rm, I0)
    m.name <http://m.name> = name;
             m.Kv = Kv;
             m.Rm = Rm;
             m.I0 = I0;
             m = class (m, "motor");
    end

    ...and one simple method:

    function power = power_out (motor, u, i)
             power = (u - i*motor.Rm) * (i - motor.I0);
    end

    ... and I created an object of the class motor:

    octave:1> m1 = motor ("Sample motor", 400, 0.05, 1);

    ... but I cannot call the power_out method using the traditional "OO
    way":

    octave:2> m1.power_out (1,1);
    error: invalid index for class

    ... only this form seems to work:

    octave:2> power_out (m1, 1, 1);

    Is it how this is supposed to be in Octave? The object.method()
    calling convention is much more intuitive and more readable than
    method(object) IMHO. Also, it clearly allows to avoid name conflicts
    if I got some global function or another method with the same name...

    Thanks,
    joanna.
    _________________________________________________
    Help-octave mailing list
    address@hidden <mailto:address@hidden>
    https://mailman.cae.wisc.edu/__listinfo/help-octave
    <https://mailman.cae.wisc.edu/listinfo/help-octave>



Hi,

according to
http://www.gnu.org/software/octave/doc/interpreter/Creating-a-Class.html#Creating-a-Class,
all class definitions must be inside folders starting with an @ symbol.
Did you do that?

Yes, I did:

address@hidden @motor]$ pwd
/rw/home/user/multirotor_tools/@motor
address@hidden @motor]$ ll
total 16
-rw-rw-r-- 1 user user 142 Oct 18 18:45 display.m
-rw-rw-r-- 1 user user 119 Oct 18 18:51 get.m
-rw-rw-r-- 1 user user 181 Oct 18 18:45 motor.m
-rw-rw-r-- 1 user user 171 Oct 18 21:14 power_out.m

joanna.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]