Really BASIC idl programming question [message #37807] |
Fri, 23 January 2004 18:20 |
u2s5thmember
Messages: 11 Registered: January 2004
|
Junior Member |
|
|
Hi everybody,
I feel really dumb asking this question, but I haven't been able to
figure out a better way to write this code... and (it will become
clear) programming obviously isn't my forte.
I have several arrays of data of the same length:
num=[data between 0 and 1 say]
temp=[data between 195 and 205 K]
and so on...
I would like to plot a histogram of % data for three different
temperature ranges
So what this means is, I pick all the data
1) where the "num" array is between 0 and 1, and "temp" is between
195-200.
2) where "numb" is between 0.1 and 1, and "temp" is between 195 and
200.
3) "num": 0.2 through 1 and "temp": 195 to 200
4) .... and so on...
repeat this for every 5 degree increment for temperature.
Basically, I THINK I would like to create an array made up of the
output of a bunch of where statements.
This lame code is what I have written, could you please help me write
this in a better/faster/not so emabarassing way?
plot, x_values, y_values, /nodata, etc, etc....
for k=0, 2 do begin
a=where((num gt 0.0) and (temp GE (195+5*k)) AND (temp LT
(200+5*k)))
b=where((num gt 0.1) and (temp GE (195+5*k)) AND (temp LT
(200+5*k)))
c=where((num gt 0.2) and (temp GE (195+5*k)) AND (temp LT
(200+5*k)))
[.......]
if (n_elements(a) GT 1) then a=n_elements(a) else a=0
if (n_elements(b) GT 1) then b=n_elements(b) else b=0
if (n_elements(c) GT 1) then c=n_elements(c) else c=0
[.......]
new_array=[a,b,c,d,e,f,g,h,i,j]
max_value=float(a)
oplot, x_values, (new_array/max_value)*100, PSYM=10
endfor
I know I should be using multidimensional arrays, but I always get
stuck trying to define "new_array" without using all these repeated
where statements.
Thanks for suffering through this! I would Dearly appreciate ANY
suggestions (other than quit programming!) ;)
thanks again!
|
|
|