Re: Increment operator
- From: Doug Schwarz <see@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 21 Oct 2005 14:12:00 GMT
In article <MPG.1dc2a9e5bc356489899cf@xxxxxxxxxxxxxxxxxx>,
Loren Shure <loren.shure@xxxxxxxxxxxxx> wrote:
> In article <see-71ED10.10482220102005@xxxxxxxxxxxxxxxxxxxx>,
> see@xxxxxxxxxxxxxxxxxxx says...
[snip]
> > ... I'll bet *most* people would be happy if
> >
> > <A> += 1
> >
> > does the same thing as
> >
> > <A> = <A> + 1
> >
> > for all possible expressions, <A>. For example,
> >
> > a(k) += 1 is equivalent to a(k) = a(k) + 1
> >
> > a.field += 1 is equivalent to a.field = a.field + 1
[snip]
>
> But there are 2 credible ways (maybe more?) to look at the expression
> Steve wrote -- which is the problem: a(k) += 1
>
> if k has repeated indices -- which is what Steve was trying to get at.
> They both map to reasonable behavior.
>
> 1) a(k) = a(k) + 1;
> for repeated k, a(k) would only increase by 1
> 2) for ind = 1:length(k)
> a(k(i)) = a(k(i)) + 1;
> end
> for repeated k, a(k) would have the +1 statements accumulate
>
> So that's the main conundrum - what behavior to have with repeated
> indices. We've asked before and gotten mixed answers before. Feel free
> to add your own thoughts now.
>
> --Loren
Hi Loren,
I understand completely about the repeated indices. I think, for
simplicity, that MATLAB should treat += as I described above. In other
words, all the += will do is obviate writing a complicated expression
twice, but will do the same thing as if it was there twice, warts and
all. So,
<expression 1> += <expression 2>
will do the same thing as
<expression 1> = <expression 1> + <expression 2>
always, including evaluating <expression 1> twice unless you know that
it won't make a difference. (In general, an index could be a function
evaluation with side effects.)
I don't think anyone asking for this feature wants to do anything fancy
with accumulation. You have to define what it will do in these unusual
cases, of course, but I don't think it matters very much as long as it
is spelled out in the documentation.
--
Doug Schwarz
dmschwarz&urgrad,rochester,edu
Make obvious changes to get real email address.
.
- References:
- Increment operator
- From: Paul Mennen
- Re: Increment operator
- From: Markus
- Re: Increment operator
- From: Paul Mennen
- Re: Increment operator
- From: Steven Lord
- Re: Increment operator
- From: Doug Schwarz
- Re: Increment operator
- From: Loren Shure
- Increment operator
- Prev by Date: Re: pixel data
- Next by Date: Area under a PDF
- Previous by thread: Re: Increment operator
- Next by thread: Re: Increment operator
- Index(es):
Relevant Pages
|