Storing values from loop in idl

  • Thread starter taylrl3
  • Start date
  • Tags
    Loop
In summary, to store values found using a loop without overwriting them, you can use an array of pointers to access the values directly after the loop is finished. This is a more efficient approach than rewriting the values in an array during each iteration of the loop.
  • #1
taylrl3
61
0
Hey!

I am using IDL and want to store the values found using a loop. The only problem is each time the loop goes round, it re-writes all the values in the array. How do I store the values for use once the loop has finished? Seems like a really simple thing to want to do, I am surprised I can't do it or havn't had to do it before. Anyways here is what I have got so far, I've had a go but it doesn't work:

for num=0, 32 do begin

DMID=(Basically I read the values into this array from 32 separate files)

result=where(DMID, count)

imin=-1
imax=0

for imin, imax do begin
imax=imax+count
DMIDs[imin:imax]=DMID
imin=imin+count
endfor

endfor

This doesn't work anyway and seems like a slightly mental way of going about it to me but its what a friend told me to do. Any help, most appreciated.
 
Technology news on Phys.org
  • #2
Thanks!The way you are trying to do it is not the most efficient way. You could use an array of pointers to store the values from each file. This way, once your loop is finished, you can access the values stored in the array of pointers directly. Here is an example of how you could do it:dimensions = 32pointer ptr[dimensions]for num=0, dimensions-1 do begin DMID=(Read the values from each file into this array) ptr[num] = pointer(DMID)endforOnce your loop is finished, you can access the values stored in the array of pointers using ptr[index], where index is the index of the array.
 

Related to Storing values from loop in idl

1. How do I store values from a loop in IDL?

In IDL, you can use the FOR loop to iterate through a set of values and store them in an array. For example, you can use the FOR loop to generate a sequence of numbers and store them in an array using the [ ] brackets.

2. Can I store values from a loop in a specific order in IDL?

Yes, you can use the INDEX function to specify the order in which the values are stored in the array. The INDEX function takes in the array and the desired order of the values as arguments.

3. How can I append values to an existing array in IDL?

You can use the APPEND function to add values to an existing array. This function takes in the existing array and the new values to be added as arguments, and returns a new array with the appended values.

4. Is it possible to store values from a loop in a matrix in IDL?

Yes, you can use the FOR loop to iterate through the rows and columns of a matrix and store values in each element. You can also use the INDEX function to specify the order of the values in the matrix.

5. Can I store values from a loop in a variable in IDL?

Yes, you can use the FOR loop to assign values to a variable in each iteration. The variable will be updated with the latest value in each iteration, and you can use it outside of the loop to access the final value.

Similar threads

  • Programming and Computer Science
Replies
11
Views
2K
  • Programming and Computer Science
Replies
1
Views
4K
  • Programming and Computer Science
Replies
9
Views
20K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
2
Replies
66
Views
4K
  • Programming and Computer Science
Replies
20
Views
2K
  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
4
Views
5K
  • Programming and Computer Science
Replies
3
Views
1K
Back
Top