For loop - Question [message #89989] |
Tue, 13 January 2015 06:02  |
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   |
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   |
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 #89997 is a reply to message #89993] |
Wed, 14 January 2015 00:55  |
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
|
|
|