[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Array subscript question
Kenneth P. Bowman (bowman@null.edu) writes:
> Can someone explain this behavior to me? I can't find anything in the
> documentation that states that repeated subscripts are handled
> differently.
>
> IDL> a = FINDGEN(5)
> IDL> i = [1, 2, 3]
> IDL> a[i] = a[i] + 10.0
> IDL> PRINT, a
> 0.00000 11.0000 12.0000 13.0000 4.00000
>
> This is the behavior I expect.
>
>
> IDL> a = FINDGEN(5)
> IDL> i = [2, 2, 2]
> IDL> a[i] = a[i] + 10.0
> IDL> PRINT, a
> 0.00000 1.00000 12.0000 3.00000 4.00000
>
> Why does it only do the operation *once* when
> IDL> HELP, a[i]
> <Expression> FLOAT = Array[3]
Uh, I'm sure it's doing the operation three times, Ken.
But always to the same value. :-)
Sounds what you want is a loop. I'm not too fond
of them in IDL, but certainly it's appropriate here.
I think the answer to your question really is this:
array subscripting operations are NOT loops!
FOR I=0,2 DO a[2] = a[2] + 10.0
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155