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

Home » Public Forums » archive » For loop - Question
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
For loop - Question [message #89989] Tue, 13 January 2015 06:02 Go to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
Hi

I create a for loop to store my Data in a 3D array [100,200,200]. Then I used my data array to calculate another matrix B as shown below:

for i=0, 99 do begin
ArrayData = C:\Users\..
endfor

B = total(ArrayData[0:4,*,*],1)/5.

A question that I have is once I used the ArrayData outside the for loop does it contains all the elements of the array or just those on the place [100,120,120]?

Thanks
Re: For loop - Question [message #89990 is a reply to message #89989] Tue, 13 January 2015 06:44 Go to previous messageGo to next message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
Den tisdag 13 januari 2015 kl. 15:02:48 UTC+1 skrev g.na...@gmail.com:
> Hi
>
> I create a for loop to store my Data in a 3D array [100,200,200]. Then I used my data array to calculate another matrix B as shown below:
>
> for i=0, 99 do begin
> ArrayData = C:\Users\..
> endfor

I assume the right hand side of "ArrayData = C:\Users\.." is really some operation where you read values from a file. But more important for your question, the left hand side has no subscripts so your loop would create a new array for each i, instantly forgetting the previous array. Is this really what you do?

>
> B = total(ArrayData[0:4,*,*],1)/5.
>
> A question that I have is once I used the ArrayData outside the for loop does it contains all the elements of the array or just those on the place [100,120,120]?

Why don't you inspect the array and see for yourself where there is data?
Re: For loop - Question [message #89991 is a reply to message #89989] Tue, 13 January 2015 06:46 Go to previous messageGo to next message
Yngvar Larsen is currently offline  Yngvar Larsen
Messages: 134
Registered: January 2010
Senior Member
On Tuesday, 13 January 2015 15:02:48 UTC+1, g.na...@gmail.com wrote:
> Hi
>
> I create a for loop to store my Data in a 3D array [100,200,200]. Then I used my data array to calculate another matrix B as shown below:
>
> for i=0, 99 do begin
> ArrayData = C:\Users\..
> endfor

I assume you mean something like this:

ArrayData = fltarr(100,200,200)
for i=0,99 do ArrayData[i,*,*] = my_get_data_from_file_function(file[i])

assuming that all the files contain data of the same size (200 x 200).

> B = total(ArrayData[0:4,*,*],1)/5.

This is the average of the first 5 images. Is this what you want?

> A question that I have is once I used the ArrayData outside the for loop does it contains all the elements of the array or just those on the place [100,120,120]?

I'm not really sure what you are asking about? ArrayData contains the elements you read into it in your loop. In the pseudocode you posted, it looks like you overwrite the array on each iteration in the loop. This is likely not what you want.

--
Yngvar
Re: For loop - Question [message #89992 is a reply to message #89991] Tue, 13 January 2015 07:14 Go to previous messageGo to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
> assuming that all the files contain data of the same size (200 x 200).

Right.

>> B = total(ArrayData[0:4,*,*],1)/5.
>
> This is the average of the first 5 images. Is this what you want?

Yes, this is what I want.

> In the pseudocode you posted, it looks like you overwrite the array on each iteration in the loop. This is likely not what you want.

Yes, this is what I have noticed. I don't want to overwrite it I want to store everything and use it afterwards.
Re: For loop - Question [message #89993 is a reply to message #89992] Tue, 13 January 2015 07:16 Go to previous messageGo to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
I forgot to write something in my for loop:

for i=0, 99 do begin
ArrayData = C:\Users\..

Data = ArrayData[i,*,*]
endfor
Re: For loop - Question [message #89997 is a reply to message #89993] Wed, 14 January 2015 00:55 Go to previous message
Yngvar Larsen is currently offline  Yngvar Larsen
Messages: 134
Registered: January 2010
Senior Member
On Tuesday, 13 January 2015 16:16:33 UTC+1, g.na...@gmail.com wrote:
> I forgot to write something in my for loop:
>
> for i=0, 99 do begin
> ArrayData = C:\Users\..
>
> Data = ArrayData[i,*,*]
> endfor

Hm. This is not very coherent. You don't show what you do with the "Data" variable. You are overwriting it on every iteration. And what does "C:\Users\..." contain? Single images of size (200,200)? In that case, your loop should be something like what I wrote in my previous post:

ArrayData = fltarr(100,200,200)
for i=0,99 do ArrayData[i,*,*] = my_get_data_from_file_function(file[i])

where "my_getdata_from_file_function" is a function that can read your files (you haven't told us what kind of files you have).

Why don't you post your actual loop and tell us what you want to do? It is hard to tell what you did and what you are trying to do. See

http://xyproblem.info

--
Yngvar
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL inverse matrix problem
Next Topic: Wavelet transform in IDL?

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

Current Time: Wed Oct 08 15:13:40 PDT 2025

Total time taken to generate the page: 0.00481 seconds