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

Home » Public Forums » archive » Adding arrays
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
Adding arrays [message #91465] Fri, 17 July 2015 00:38 Go to next message
Dete van Eeden is currently offline  Dete van Eeden
Messages: 32
Registered: July 2015
Member
Hallo,

I am trying to add arrays together in a for loop but the end result is just equal to the last array.

for k=0,5 do begin

read in the array etc.

final = final + array

endfor

The final is suppose to be the sum of all the arrays.

Thank you!
Re: Adding arrays [message #91468 is a reply to message #91465] Fri, 17 July 2015 02:26 Go to previous messageGo to next message
Nikola is currently offline  Nikola
Messages: 53
Registered: November 2009
Member
On Friday, July 17, 2015 at 8:39:01 AM UTC+1, Dete van Eeden wrote:
> Hallo,
>
> I am trying to add arrays together in a for loop but the end result is just equal to the last array.
>
> for k=0,5 do begin
>
> read in the array etc.
>
> final = final + array
>
> endfor
>
> The final is suppose to be the sum of all the arrays.
>
> Thank you!

You somehow overwrite your variable f within the loop (if f is reset to 0 for every k, the final result is clearly just the last element). If it is not obvious, perhaps it's in a subfunction that your calling in the loop?
Re: Adding arrays [message #91471 is a reply to message #91465] Fri, 17 July 2015 09:42 Go to previous messageGo to next message
Dete van Eeden is currently offline  Dete van Eeden
Messages: 32
Registered: July 2015
Member
Makes sense...

How do I define an array that consists of 5 arrays each with 256x256 elements?

For example final(k) is the sum of the arrays from 1 to 5 and final=fltarr(256,256)

It seems so simple but I cant get it right :-)
Re: Adding arrays [message #91473 is a reply to message #91471] Fri, 17 July 2015 11:26 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Dete van Eeden writes:

> How do I define an array that consists of 5 arrays each with 256x256 elements?
>
> For example final(k) is the sum of the arrays from 1 to 5 and final=fltarr(256,256)
>
> It seems so simple but I cant get it right :-)

total = FltArr(256,256)
data = FltArr(256, 256, 5)
FOR j=0,4 do total = Temporary(total) + data[*,*,j]

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Adding arrays [message #91474 is a reply to message #91473] Fri, 17 July 2015 11:36 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

>
> Dete van Eeden writes:
>
>> How do I define an array that consists of 5 arrays each with 256x256 elements?
>>
>> For example final(k) is the sum of the arrays from 1 to 5 and final=fltarr(256,256)
>>
>> It seems so simple but I cant get it right :-)
>
> total = FltArr(256,256)
> data = FltArr(256, 256, 5)
> FOR j=0,4 do total = Temporary(total) + data[*,*,j]

Or, the IDL Way:

data = Randomu(seed, 256,256,5)
total = Total(data, 3)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Adding arrays [message #91480 is a reply to message #91474] Sun, 19 July 2015 05:34 Go to previous messageGo to next message
Dete van Eeden is currently offline  Dete van Eeden
Messages: 32
Registered: July 2015
Member
Thank you very much :-)
Re: Adding arrays [message #91481 is a reply to message #91480] Mon, 20 July 2015 00:34 Go to previous message
dete.liebenberg is currently offline  dete.liebenberg
Messages: 1
Registered: July 2015
Junior Member
On Sunday, July 19, 2015 at 2:34:32 PM UTC+2, Dete van Eeden wrote:
> Thank you very much :-)

Is there a reason why this would work for 3 dimensions but not 2.

If a have data=fltarr(256,4)

the total is equal to the last array again?

Thank you
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: creating arrays in loops
Next Topic: Creating KML error

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

Current Time: Wed Oct 08 09:14:52 PDT 2025

Total time taken to generate the page: 0.00512 seconds