comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Storing values in array after each iteration in for loop
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Storing values in array after each iteration in for loop [message #91265] Wed, 24 June 2015 15:44 Go to next message
kcs4315 is currently offline  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 #91266 is a reply to message #91265] Wed, 24 June 2015 20:41 Go to previous messageGo to next message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
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)
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 Go to previous message
Jeremy Bailin is currently offline  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.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: cgScaleVector and diverging colorbar help
Next Topic: Identifying outliers in data

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 07:14:56 PDT 2025

Total time taken to generate the page: 0.00752 seconds