Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Reason Matlab has never implemented incrementation operators?
Date: Thu, 1 Oct 2009 09:47:42 -0400
Organization: The MathWorks, Inc.
Lines: 49
Message-ID: <ha2bt5$ajg$1@fred.mathworks.com>
References: <20461488.1237405703543.JavaMail.jakarta@nitrogen.mathforum.org> <ha1d12$log$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1254404837 10864 172.31.44.65 (1 Oct 2009 13:47:17 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 1 Oct 2009 13:47:17 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:574231



"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