+=, -=, *=, /= operators

+=, -=, *=, /= operators

Post by Michael Robbin » Sat, 05 Jan 2002 01:48:12



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;

Michael Robbins, CFA
Director, Debt Capital Markets
CIBC World Markets Corp., Canadian Imperial Bank of Commerce
New York, NY   USA

 
 
 

+=, -=, *=, /= operators

Post by Doug Schwar » Sat, 05 Jan 2002 02:34:27




>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;

You can't.  This would require modifying the parser.

--
Doug Schwarz
Eastman Kodak Company


 
 
 

+=, -=, *=, /= operators

Post by Johan Kullsta » Sat, 05 Jan 2002 05:45:47



> 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;

you might want to try octave.

GNU Octave, version 2.1.34 (i386-redhat-linux-gnu).
.....
jk:1> a = 3
a = 3
jk:2> a += 2
a = 5
jk:3>

--
J o h a n  K u l l s t a m

sysengr

 
 
 

+=, -=, *=, /= operators

Post by Abe Kohe » Sat, 05 Jan 2002 05:47:05





> >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;

> You can't.  This would require modifying the parser.

OK. Same as you wrote for Michael's question on the ?: operator. But is
there a published grammar, so we won't need to ask questions like these?

Abe

 
 
 

+=, -=, *=, /= operators

Post by Scott Seidma » Sat, 05 Jan 2002 06:11:11



102750.news.dfncis.de:





>> >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;

>> You can't.  This would require modifying the parser.

> OK. Same as you wrote for Michael's question on the ?: operator. But is
> there a published grammar, so we won't need to ask questions like these?

> Abe

I don't know if MW publishes one, but there is some interesting stuff at
http://citeseer.nj.nec.com/cachedpage/290244/1

Weird way to publish a document, though.

Scott

 
 
 

+=, -=, *=, /= operators

Post by John William » Sat, 05 Jan 2002 08:39:57



> 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;

As others have pointed out, it seems impossible to create exactly this
synax.  However, slightly evil use of mex functions could achieve
something like

inc(A,7);     % A=A+7
dec(A,B);     % A=A-B

and so on.

Apparently there are mex library calls which make this behaviour safe,
something to do with "unsharing" an array.

Regards,

John

 
 
 

+=, -=, *=, /= operators

Post by Cleve Mol » Sat, 05 Jan 2002 10:48:30



> 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?

  -- Cleve

 
 
 

+=, -=, *=, /= operators

Post by Abe Kohe » Sat, 05 Jan 2002 11:57:23




> > 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.

All the operators Michael asked for are common to C/C++/Java. There is a
large universe of programmers fluent in at least one of these three
languages. (Yes, I know MIT still teaches 6.001 in Lisp.)

Besides if you are going to give us the "bad part" of Java, witness all the
memory problems and how many of us run with the nojvm option, you might as
well give us some of the "good parts" of Java, as well.

Abe

 
 
 

+=, -=, *=, /= operators

Post by John William » Sat, 05 Jan 2002 13:09:48



> 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?

For me, it's reasons 1,2 and 4.  My other reason is that in-place
operators may permit computation on larger arrays the currently
possible.  For instance, the statement

I=I*0.5

requires twice the storage size of I - in my work I regularly run out of
memory doing exactly such computations (huge images).  In-place
operators would allow me to sail a little bit closer to the wind in
terms of memory and image size.

Regards,

John

PS Any clues why I might be getting out of memory errors on a machine
with 32GB of physical memory (60 processor SGI beast running IRIX 6.5)?
I max out at about 900MB membery used (according to WHOS).

>   -- Cleve


--
Dr John Williams,    Postdoct*Research Fellow
High Performance Computing Group, CRC for Satellite Systems
Queensland University of Technology,   Brisbane,  Australia
Phone : (+61 7) 3864 2427           Fax : (+61 7) 3864 1517
Web   : http://www.veryComputer.com/
 
 
 

+=, -=, *=, /= operators

Post by Jeffery J. Leade » Sat, 05 Jan 2002 13:24:03




Quote:>>   *  you would like MATLAB to look more like C?
[...]
>     * you would like MATLAB to look more like Java.

This would be a step backward for me; I can use MATLAB in a wide
variety of courses because the syntax is so easy and natural. Since
this uses the + sign in a way that isn't familiar from matrix algebra
it isn't as easy as saying "don't teach it"--someone will do this by a
typo sooner or later and I'd rather have them get an error.

Ah, more compact and less readable notation...all roads lead to APL.

If it would address the point made by John Williams in Message-ID:

of having it over trying to write a special routine to avoid that
issue.

 
 
 

+=, -=, *=, /= operators

Post by John W. Eat » Sat, 05 Jan 2002 14:00:35






> > > 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.

And

  * it simplifies expressions like

      x(some_hairy_index_expression) = x(some_hairy_index_expression) OP y;

    to just

      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);
  endfor

(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

jwe

--
www.octave.org        | Unfortunately we were hoplessly optimistic in 1954
www.che.wisc.edu/~jwe | about the problems of debugging FORTRAN programs.
                      |                                       -- J. Backus

 
 
 

+=, -=, *=, /= operators

Post by Lars Gregers » Sat, 05 Jan 2002 16:27:53








>> >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;

>> You can't.  This would require modifying the parser.

But Michael may be able to overcome his problems with a neat Perl
script that changes the C syntax into Matlab syntax.

Quote:>OK. Same as you wrote for Michael's question on the ?: operator. But is
>there a published grammar, so we won't need to ask questions like these?

No, not for Matlab. The grammar for GNU Octave is available though
(but it is pretty complex).

  Lars


2-control ApS
Windows Toolbox for Matlab version 1.0: www.2-control.com/wt/

 
 
 

+=, -=, *=, /= operators

Post by John D'Erric » Sat, 05 Jan 2002 21:13:30





> > 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?

>   -- Cleve


I'd chose reason 1 mainly. I think Its easy to
understand the notation.

Reason 4 also very much applies for me, because
I hate to type lines like:

  my_long_variable_name=my_long_variable_name+1;

But I'd never, ever, ever, do anything just so
it could make matlab look like C. I've heard
that programming in C causes cancer in
laboratory rats. It may be just a rumor, but
I'd not want to take that chance.  ;-))

John

--

 
 
 

+=, -=, *=, /= operators

Post by Michael Robbin » Sat, 05 Jan 2002 22:04:47


Quote:>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?

Thank you for your interest.  The notation is nice as many have mentioned in
this thread.  I imagine it would be faster.  But my main concern is prototyping
and updating MEX files.

Unfortunately MATLAB cannot be everything to everyone and I often have to write
MEX files to augment MATLAB's speed or capabilities.  I usually prototype in
MATLAB and run a script to convert MATLAB syntax to C.  If I have to change a C
function I try to convert it back.

The less conversion I have to do, the better.

Besides, I like C syntax; I just don't like its rigor.

Michael Robbins, CFA
Director, Debt Capital Markets
CIBC World Markets Corp., Canadian Imperial Bank of Commerce
New York, NY   USA

 
 
 

1. logical operator for 2 vectors of textdata

How do I test for equality of a textdata from one vector and a
testdata from another?

Example:
vector_a(1) = 'iloveyou'
vector_b(1) = 'ihateyou'

I tried to use the equality operator:
if vector_a(1) == vector_b(1)

Unfortunately, MatLab registered the following error message:

Function '==' is not defined for values of class 'cell'.

Please help. Thanks.

2. Trouble with M98 Internet Quotes

3. Single precision operators

4. CCT User's Group Call for Papers

5. element wise relational operator

6. Show all commands in drop down?

7. Speed problem morphological operators

8. ISA Killing Outgoing Mail

9. why Matlab changed its logic operator in its statistics toolbox?

10. Receiver operator characteristic analysis

11. relational operators to determine range

12. Equivalent Operator? ++

13. How can make a flood-fill like.operator on a Figur