Storing values in array after each iteration in for loop [message #91265] |
Wed, 24 June 2015 15:44  |
kcs4315
Messages: 2 Registered: March 2015
|
Junior Member |
|
|
Hi,
I'm very new to IDL....
Essentially what I want to do is after each iteration of a for loop, store the value it produces in an array. I originally tried making the array in the for loop but it was over written every time it went through an iteration, so only the last value was stored and everything else was 0. Is there an easy way to remedy this?
|
|
|
|
Re: Storing values in array after each iteration in for loop [message #91305 is a reply to message #91266] |
Sat, 27 June 2015 09:58  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Wednesday, June 24, 2015 at 11:41:50 PM UTC-4, Michael Galloy wrote:
> On 6/24/15 4:44 PM, kcs4315@g.rit.edu wrote:
>> Hi,
>>
>> I'm very new to IDL....
>>
>> Essentially what I want to do is after each iteration of a for loop,
>> store the value it produces in an array. I originally tried making
>> the array in the for loop but it was over written every time it went
>> through an iteration, so only the last value was stored and
>> everything else was 0. Is there an easy way to remedy this?
>
> I imagine it would be something like:
>
> x = fltarr(n)
> for i = 0L, n - 1L do begin
> x[i] = ; whatever processing you want to do here
> endfor
>
> Mike
> --
> Michael Galloy
> www.michaelgalloy.com
> Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
It's also worth noting that, depending on what exactly you're doing inside the for loop, you may be able to operate on full arrays at once instead of using a for loop. :)
-Jeremy.
|
|
|