> > > How would I make +=, -=, *=, /= operators so that I can make my matlab
> > > functions work like C functions in this way;
> > > a+=7;
> > > instead of
> > > a=a+7;
> > Why would you like to see this added to MATLAB? Is it because
> > * you like the notation?
> > * you think it could be faster?
> > * you would like MATLAB to look more like C?
> > * some other reason?
> We can add:
> * you would like MATLAB to look more like Java.
* it simplifies expressions like
x(some_hairy_index_expression) = x(some_hairy_index_expression) OP y;
x(some_hairy_index_expression) OP= y;
and, if implemented cleverly, might even be faster to evaluate and
save some memory.
Octave has these operators, but they don't speed things up or save
memory (yet). Expressions of the form
x(index) OP= y;
are just convenient shorthand for
x(index) = x(index) OP y;
One problem that has come up a few times for Octave users is that
given something like
x = some_vector ();
y = [1, 2, 3, 4];
i = [1, 1, 2, 2];
some people want expressions like
x(i) += y;
to be equivalent to
for j = 1:length(i)
x(i(j)) = x(i(j)) + y(j);
(or something similar) which, although it might be useful, is not at
all the same as
x(i) = x(i) + y;
If you are going to follow C here, it seems to me that it's probably
best to restrict the meaning of
x(idx) OP= y
to be exactly equivalent to
x(idx) = x(idx) OP y
www.octave.org | Unfortunately we were hoplessly optimistic in 1954
www.che.wisc.edu/~jwe | about the problems of debugging FORTRAN programs.
| -- J. Backus