f



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?

0
g
12/24/2014 11:52:11 AM
comp.lang.idl-pvwave 12260 articles. 4 followers. Post Follow

3 Replies
6129 Views

Similar Articles

[PageSpeed] 4

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
3
Helder
12/24/2014 2:28:50 PM
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?
0
wlandsman
12/24/2014 3:00:38 PM
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
0
David
12/27/2014 6:32:39 PM
Reply:

Similar Artilces:

Envi_get_slice error (subscript range error)
Hello Everyone, I am trying to loop through every pixel in the image to extract its value. I have aimage of dimension 5035*5132. I tried to use the envi_get_slice to extract the pixel values. Bu i get the error that says Subscript range values of the form low:high must be >= 0, < size, with low <= high: <FLOAT Array[5035]>. My command is: for i=0, (NumCols - 1) do begin ;print, i for j=0, (NumRows - 1) do begin ; print, j y_val=envi_get_slice(fid=fid1,line=j, xs=i, xe=i) I have just started using IDL. So I maybe doing somthing very stupid. Any help is much ap...

testing for a range in Excel from Access, subscript out of range error
Hi I am creating 3 worksheets in a workbook from Access VBA, copying Access da= ta on sheets 2 & 3, grouping values, totalling and defining named ranges fo= r the totals, all in VBA. I use these ranges to summarize on Sheet (1) but = sometimes certain ranges don't get made as the data value does not occur. M= y summary forumlas add ranges together but fail if a range did not get crea= ted=20 I have been trying to employ the code found in article below to test for r= ange first so I can adjust summary formula ..vbaexpress.com/kb/getarticle.php?kb_id=3D729 (code pasted below also) ...

Odd Excel Link error (Run time error 9, subscript out of range)
Hi. I just started up excel link and make a button. This button only excuted two lines of code, both of which function completely within Matlab itself. The first line simply tells Matlab to define a path. The second line calls a function I have written which automatically reads in a few seperate/unrelated csv files and creates variables in Matlab of them. This function has no problems with it when I run it in Matlab normally. Nothing in these two lines takes anything from Excel or sends anything back. It all takes place in Matlab. But, whenever I press the button to run those two lines of co...

IDL out of range error
Hi, I have an error that has been bugging me for 3 weeks that I am hoping you could shed some light on. I am currently trying to create a subset of an image from a bigger image and comparing it to another subset of the same dimention. When I run the program however I recieve an error: Subscript range values of the form low:high must be >= 0, < size, with low <= high: I have checked my array and it is in the form: im=image_file(X1:X2, Y1:Y2) below is actual line: sub = new_image2(x0:x0+L-1, y0:y0+L-1) where x0 and y0 is the coordinate on the large image that...

ERROR: Array subscript out of range
Hi, Is there any special way to find out where the subscript in an array is reaching out of bound? How can I make SAS to tell me which array? I have a group of arrays and after I have checked all the loops I think the indices are set up correct. But still SAS is saying: ERROR: Array subscript out of range at line 6691 column 190 I would appreciate any input. TIA, Aldi Partial program: ================ do j=1 to &nphenos; put "step0 reached here " j= i= ; if i>2 then do; grs{j,i} = .5*grs{j,1} + .5*grs{j,2} + ...

Error 9: Subscript out of range
Hello guru's! I have the following code that generates an error. The error occures at the line CommandBars("OK Revisie").Controls(vLaag1).Controls(vLaag2).vAction = Vstate With the command ?vAction in the Immediate Window I can see that vAction gets the right value but in the line where the error is generated it is empty. All the other variables neatly display their value when pointing at them in the forementioned line. I have been looking into this but all I can find are articles related to either an Excel-bug or arrays. I can not find a relation between those two and my prob...

Subscript out of range error while not using array.
I have a form that is used every day to create quotes. However, every 2 weeks or so a user would randomly get an error 9 - subscript out range message. I'm not using any array in this form. Does anyone know that else might possibly trigger this error besides array? Thanks Julie Other causes of this error are: - a problem wizard; - a problem reference; - code that is being interpreted wrongly; - a corruption. Regarding the wizard problem, see: http://support.microsoft.com/default.aspx?scid=kb;en-us;306326 If the problem occurs under a predictable set of circumstances, you could ...

Re: ERROR: Array subscript out of range
> From: aldi [mailto:aldi@WUBIOS.WUSTL.EDU] > Is there any special way to find out where the subscript in > an array is reaching out of bound? How can I make SAS to tell > me which array? > I have a group of arrays and after I have checked all the > loops I think the indices are set up correct. > But still SAS is saying: > ERROR: Array subscript out of range at line 6691 column 190 well, that's what line numbers are for! generally this error message means that you're still in the loop and have gone past the upper bound. check the array reference in column 19...

Re: ERROR: Array subscript out of range #3
> From: aldi [mailto:aldi@wubios.wustl.edu] > You see, I answered you and I did not ask you a very simple > question: (Because I have included some line space now the > error is saying line 6694 col 206.) > > You mentioned "that's the line and column are for..." > > My program is a group of programs and a good part of them > expressed in > macro language: how do you count the lines to match with what SAS is > reporting? > > Right now if I go to the log, where SAS is reporting the > error the line > number is 279,334. If I return to the...

Run-Time Error �9�: Subscript Out of Range
I have been developing a VB6 program to read the records from an Access 2003 database and output a report. I got the program to run correctly in development mode. It would output the report just like I wanted. Then I saved everything and created an executable file of the program. When I run the executable using the same exact database (executable program and access file are in the same folder) I get a �run-time error 9� - subscript out of range�. This is a new one for me. In the past, everything that I got working in design or development mode worked the same in executable mode u...

IDL and IDL-PVWAVE disambiguation
Hi I've noticed that a few open source IDL projects are finding themselves on sourceforge. However, the IDL category seems to have a mixture of both "Interface Definition Language" and "Interactive Data Language". Would it make more sense to have an IDL-PVWAVE category, or perhaps an IDL-ENVI category? https://sourceforge.net/tracker/?func=detail&atid=350001&aid=1821007&group_id=1 Robbie ...

Re: ERROR: Array subscript out of range #2
From: Aldi Kraja [mailto:aldi@wubios.wustl.edu] Here follow two examples of declaring the arrays in advance since you asked: array rgs{&nphenos,&maxmems} %do j=1 %to &nphenos; RG&j._F RG&j._M RG&j._1-RG&j._&maxkids %end; ;;;; array ggs{&nloci,&maxmems} %do k=1 %to &nloci; GG&k._F GG&k._M GG&k._1-GG&k._&maxkids %end; ;;;; ah, so! well, macro wizardry happening, I note that you're declaring a two-dimensional array and will assume that the value of MaxMems is RG&j._F RG&a...

motor: error: expected M-b~@~X(M-b~@~Y before M-b~@~XargcM-b~@~Y
I am trying to write a small C test program using the motor development environment. I tried to use the cut text facility (using Alt-X), and this put some sort of marker: M-CM-8 in the left hand margin of the program. Anyway, I didn't know what I was doing here, so I deleted the markers, and cut the text by moving the cursor and repeatedly pressing the delete key. I had a few attempts at this, using the F3, and various other keys, but I haven't figured this out yet. (My background is with MSDOS and Microsoft Programmer's Workbench.) Anyhow, I have now come to build the pr...

Getting "vector subscript out of range" error
when I exe my project in vs.net2005,I got the error following: Debug Assertion Failed! Program:........ File:c:\program files\microsoft visual studio 8\vc\include\vector Line:756 Expression:vector subscript out of range. I just push_back some int less than 30 to the vector. But in the DevC+ +5.0,everything is all right. Could anyone give me some hint what is the wrong thing i made? On Nov 13, 11:35 am, Han <Mingwei....@gmail.com> wrote: > when I exe my project in vs.net2005,I got the error following: > Debug Assertion Failed! > Program:........ > File:c:\program files\...

Web resources about - ERROR: Attempt to subscript B with is out of range - comp.lang.idl-pvwave

Subscript and superscript - Wikipedia, the free encyclopedia
... article contains special characters . Without proper rendering support , you may see question marks, boxes, or other symbols . Example of subscript ...

subscript - YouTube
subscript - YouTube

Tips for WordPress Bloggers: Preview, Quotation Marks, Code, and Subscripts and Superscripts
It?s now more than two months since I started blogging. It has not always been trouble-free. Two months ago, all I knew about WordPress was that ...

Iota subscript - Wikipedia, the free encyclopedia
The iota subscript is a diacritic mark in the Greek alphabet shaped like a small vertical stroke or miniature iota 〈 ι 〉 placed below the letter. ...

Subscript and superscript - Wikipedia, the free encyclopedia
... article contains special characters . Without proper rendering support , you may see question marks, boxes, or other symbols . Example of subscript ...

Resources last updated: 1/26/2016 3:23:23 AM