|
"Ryan Ollos" <ryano@physiosonics.com> wrote in message
news:ha1d12$log$1@fred.mathworks.com...
> klydefrog <aj00mcgraw@gmail.com> wrote in message
> <20461488.1237405703543.JavaMail.jakarta@nitrogen.mathforum.org>...
>> What is the philosophy or reason behind the Mathworks not finally
>> releasing Matlab with a few incrementation operators? (++, +=, etc)
>
> It would be interesting, given the new object oriented programming
> capabilities of MATLAB, if it were possible to define operators such as
> this for your own class. With that in mind, it would also be nice if one
> could then implement their own ++ operator for the intrinsic classes.
You can't define _operators_ for your own classes, but you could define your
own _methods_ for a class. For instance, you could write a method with the
following signature for a handle class:
function plusequals(obj, x)
and use it where you would use a "+=" operator:
plusequals(myobject, incrementdata)
Of course, depending on how 'fancy' you want to get, you could have your
method accept indices as well:
function plusequals(obj, indices, x)
but then you'd have to figure out how you want to handle things like
repeated indices.
> I'm fairly sure that this is not currently possible, although I think it
> is possible to overload the operators that are pre-defined in MATLAB, such
> as + and - (via `plus` and `minus` methods). If I remember correctly,
> I've seen examples of this in pre-2008a classes, but have never tried it
> myself.
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/f1-6010.html
and
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/br02zhv.html
--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|