Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
ERROR: Attempt to subscript B with is out of range
Hi I've got a 3D array B[100,200,200]. My array B sometimes contains negative values and other times very large values. In order to make sure that when there are either negative or very large values will set to zero I wrote the following code: FOR i=0L,199 DO BEGIN FOR j=0L,199 DO BEGIN WRONG = total((B[*,i,j] LT 0) OR (B[*,i,j] GT 10000)) IF WRONG GT 0 THEN B[*,i,j]=0 ENDFOR ENDFOR I got the error Attempt to subscript B with j is out of range. I cannot figure out with this happen with the j variable. Any idea?
Re: ERROR: Attempt to subscript B with is out of range
On Wednesday, December 24, 2014 12:52:13 PM UTC+1, g.na...@gmail.com wrote: > Hi > > I've got a 3D array B[100,200,200]. My array B sometimes contains negative values and other times very large values. In order to make sure that when there are either negative or very large values will set to zero I wrote the following code: > > FOR i=0L,199 DO BEGIN > FOR j=0L,199 DO BEGIN > WRONG = total((B[*,i,j] LT 0) OR (B[*,i,j] GT 10000)) > IF WRONG GT 0 THEN B[*,i,j]=0 > ENDFOR > ENDFOR > > I got the error Attempt to subscript B with j is out of range. I cannot figure out with this happen with the j variable. Any idea? Hi, that's not the IDL way. Here is one way of doing it (didn't check, but I think it is also a lot faster): ;create an array b = long(randomu(s,100,200,200)*100) b[50,100,100] = -12 b[51,101,101] = 20000 ;look for the bad values pos = where((a lt 0) or (a gt 10000), cnt) if cnt gt 0 then b[pos]=0l There are other ways of doing this sort of search for values in an array. Have a look at older posts. Cheers, h
I don't know why you are getting a subscript error. But have you done any debugging? In particular 1. What line number does the subscript error occur in? 2. What are the values of I and J when the subscript error occurs? 3. Can you confirm that the array B is still dimensioned 100x 200x200 when the error occurs? Usually, when I have an error that shouldn't occur, it is because one of my assumptions is faulty. --Wayne On Wednesday, December 24, 2014 6:52:13 AM UTC-5, g.na...@gmail.com wrote: > Hi > > I've got a 3D array B[100,200,200]. My array B sometimes contains negative values and other times very large values. In order to make sure that when there are either negative or very large values will set to zero I wrote the following code: > > FOR i=0L,199 DO BEGIN > FOR j=0L,199 DO BEGIN > WRONG = total((B[*,i,j] LT 0) OR (B[*,i,j] GT 10000)) > IF WRONG GT 0 THEN B[*,i,j]=0 > ENDFOR > ENDFOR > > I got the error Attempt to subscript B with j is out of range. I cannot figure out with this happen with the j variable. Any idea?
On Wednesday, December 24, 2014 6:52:13 AM UTC-5, g.na...@gmail.com wrote: > Hi > > I've got a 3D array B[100,200,200]. My array B sometimes contains negative values and other times very large values. In order to make sure that when there are either negative or very large values will set to zero I wrote the following code: > > FOR i=0L,199 DO BEGIN > FOR j=0L,199 DO BEGIN > WRONG = total((B[*,i,j] LT 0) OR (B[*,i,j] GT 10000)) > IF WRONG GT 0 THEN B[*,i,j]=0 > ENDFOR > ENDFOR > > I got the error Attempt to subscript B with j is out of range. I cannot figure out with this happen with the j variable. Any idea? 1. Here's a nice idiom for setting negative values to zero b = b > 0. An even more compact version: b >= 0. 2. Masking large values similarly is quick and easy threshold = 10000 b = b * (b le threshold) The more compact version is b *= b le threshold Summarizing the quick way to achieve your goals b >= 0. ; set negative values to zero b *= b le threshold ; set large values to zero TTFN, David