HELP adding arrays [message #91536] |
Sun, 26 July 2015 08:30  |
Dete van Eeden
Messages: 32 Registered: July 2015
|
Member |
|
|
Hallo
I have posted before but I still cant add arrays together!
I have tried the total command:
finaal=fltarr(1508)
values=fltarr(1508,6)
finaal=total(values,2)
finaal is equal to the last array...
I have also tried
finaal=fltarr(1508)
values=fltarr(1508,6)
finaal=temporary(finaal) + values[*,j]
finaal is Still equal to the last array
What the hell?!
It cant be that difficult......
|
|
|
Re: HELP adding arrays [message #91537 is a reply to message #91536] |
Sun, 26 July 2015 10:41   |
dg86
Messages: 118 Registered: September 2012
|
Senior Member |
|
|
On Sunday, July 26, 2015 at 11:30:16 AM UTC-4, Dete van Eeden wrote:
> Hallo
>
> I have posted before but I still cant add arrays together!
>
> I have tried the total command:
>
> finaal=fltarr(1508)
> values=fltarr(1508,6)
>
> finaal=total(values,2)
>
> finaal is equal to the last array...
>
> I have also tried
>
> finaal=fltarr(1508)
> values=fltarr(1508,6)
>
> finaal=temporary(finaal) + values[*,j]
>
> finaal is Still equal to the last array
>
> What the hell?!
>
> It cant be that difficult......
Your "values" all have the value zero. The sum is working, but you're
only adding up the value zero. Try this ...
IDL> values = findgen(5, 6) ; create a small index array for demo
IDL> finaal = total(values, 2) ; sum over the second dimension
IDL> print, finaal
75.000000 81.000000 87.000000 93.000000 99.000000
It works!
All the best,
David
|
|
|
|
|
Re: HELP adding arrays [message #91540 is a reply to message #91536] |
Sun, 26 July 2015 10:51   |
Dete van Eeden
Messages: 32 Registered: July 2015
|
Member |
|
|
for j=0,5 do begin
...go to the filename etc....
openr,l,File4,/get_lun
readf,l,val
values(*,j) = val
free_lun
finaal =temporary(finaal) + values[*,j]
or finaal = total(values,2)
endfor
it doesnt work
|
|
|
Re: HELP adding arrays [message #91542 is a reply to message #91540] |
Sun, 26 July 2015 12:41  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Dete van Eeden writes:
> for j=0,5 do begin
>
> ...go to the filename etc....
>
> openr,l,File4,/get_lun
>
> readf,l,val
>
> values(*,j) = val
>
> free_lun
>
> finaal =temporary(finaal) + values[*,j]
>
> or finaal = total(values,2)
>
> endfor
>
> it doesnt work
Uh, take the TOTAL calculation out of your loop. :-)
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.")
|
|
|