Selecting a Section of an Array in IDL

In summary, The IDL function "where" can be used to select a specific section of an array based on a given condition. This can be helpful when working with large datasets, such as a .wav file with 300000 data points. The function has a format of where(array ge start_value and array le end_value, npts). This will create a new array with the specified section of the original array and provide the number of elements in the new array.
  • #1
big man
254
1

Homework Statement


I'm looking for a function in IDL that will select a certain section of an array.


The Attempt at a Solution


I could technically do this in a loop, but I saw that another student in my lab had a real simple single line function. I'm reading in a .wav file, which has 300000 data points and I'm wanting to select points 20000 to 60000.

For the loop I can do:

data=fltarr(40000)
for i=0, 39999 do data(i) = temp(i+20000)

But yeah I was just wondering if anyone knew what function I'm trying to describe in IDL. The function had this vague format:

......(20000:60000)
 
Physics news on Phys.org
  • #2



Hello there,

It sounds like you are looking for the IDL function "where". This function allows you to select a certain section of an array based on a specified condition. For your specific case, you could use it like this:

data = where(temp ge 20000 and temp le 60000, npts)

This will create a new array called "data" that only contains the elements of "temp" that fall within the range of 20000 to 60000. The "npts" variable will give you the number of elements in the new array.

I hope this helps! Let me know if you have any further questions.

 
  • #3



I would suggest using the IDL function "where" to select a certain section of an array. This function allows you to specify a condition and returns the indices of elements that satisfy that condition. In this case, you could use the condition "i ge 20000 and i le 60000" to select the desired section of the array. The code would look something like this:

data=fltarr(40000)
indices = where(i ge 20000 and i le 60000)
selected_data = data(indices)

This will create an array "selected_data" with the values from 20000 to 60000 in the original "data" array. This method is more efficient than using a loop and can be easily modified for different sections of the array.
 

Related to Selecting a Section of an Array in IDL

1. How do I select a specific section of an array in IDL?

To select a section of an array in IDL, you can use the SQUARE BRACKET notation. For example, if you have an array called "data" and you want to select elements 2 to 5, you can use "data[2:5]". This will return a new array with only those elements.

2. Can I select multiple sections of an array at once in IDL?

Yes, you can select multiple sections of an array at once in IDL by using the COMMA notation. For example, if you want to select elements 2 to 5 and elements 8 to 10, you can use "data[2:5, 8:10]". This will return a new array with both sections included.

3. How do I select a specific row or column of a 2D array in IDL?

To select a specific row or column of a 2D array in IDL, you can use the SQUARE BRACKET notation with a colon (:) to indicate all elements in that dimension. For example, if you have a 2D array called "data" and you want to select all elements in the 3rd row, you can use "data[2, :]".

4. Is there a way to select elements from an array based on certain conditions in IDL?

Yes, you can use the WHERE function in IDL to select elements from an array based on certain conditions. For example, if you want to select all elements in an array "data" that are greater than 10, you can use "data[WHERE(data gt 10)]". This will return a new array with only the elements that meet the condition.

5. Can I use variables to specify the sections of an array I want to select in IDL?

Yes, you can use variables to specify the sections of an array you want to select in IDL. For example, you can define a variable "index" with the values 2 to 5, and then use "data[index]" to select those elements. This allows for more flexibility and dynamic selection of array sections.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
2
Replies
43
Views
4K
  • Programming and Computer Science
Replies
17
Views
2K
  • Other Physics Topics
Replies
12
Views
2K
  • Programming and Computer Science
Replies
13
Views
1K
  • Programming and Computer Science
Replies
1
Views
4K
  • Programming and Computer Science
Replies
8
Views
2K
  • Introductory Physics Homework Help
Replies
10
Views
2K
Replies
2
Views
987
  • Programming and Computer Science
Replies
7
Views
2K
Back
Top