Discussion:
how to deal with problem:Loop limit expression too large for loop variable type.
(too old to reply)
M***@gmail.com
2008-04-04 12:08:00 UTC
Permalink
i just code a for function
for i=0, ArraySize do begin
if (Seg_Grey_Image[i] le 255) and (Seg_Grey_Image[i] ge 240) then
begin
Seg_Grey_Image[i]=255
endif
endfor
however, the error is :Loop limit expression too large for loop
variable type.
it seems this 'ArraySize' is too big. how can I deal with this
problem?
Thank you!
Allan Whiteford
2008-04-04 12:24:05 UTC
Permalink
Post by M***@gmail.com
i just code a for function
for i=0, ArraySize do begin
if (Seg_Grey_Image[i] le 255) and (Seg_Grey_Image[i] ge 240) then
begin
Seg_Grey_Image[i]=255
endif
endfor
however, the error is :Loop limit expression too large for loop
variable type.
it seems this 'ArraySize' is too big. how can I deal with this
problem?
Thank you!
Change:

"for i=0, ArraySize do begin"

to

"for i=0L, ArraySize do begin"

(note the addition of a capital 'L' after the zero).

If you set your loop variable to be a normal (2 byte) integer you can
only loop up to 32,768. Adding in the 'L' sets it to a long (4 byte)
integer.

Thanks,

Allan
M***@gmail.com
2008-04-05 06:13:55 UTC
Permalink
OK, I get that, seem I always some details in programming. thank you!
a***@gmail.com
2008-04-05 08:24:51 UTC
Permalink
Post by M***@gmail.com
OK, I get that, seem I always some details in programming. thank you!
But you better use the WHERE function for problems like these:

locs = WHERE((Seg_Grey_Image LE 255) AND (Seg_Grey_Image GE 240))
Seg_Grey_Image[locs]=255

Do not forget to also look at the minimum and maximum operator < and
Post by M***@gmail.com
, or the memory efficient variants <= and >= . They might give you
more ideas to solve your problems.

Cheers,

-Armand
David Fanning
2008-04-05 13:07:31 UTC
Permalink
Post by a***@gmail.com
Post by M***@gmail.com
OK, I get that, seem I always some details in programming. thank you!
locs = WHERE((Seg_Grey_Image LE 255) AND (Seg_Grey_Image GE 240))
Seg_Grey_Image[locs]=255
Do not forget to also look at the minimum and maximum operator < and
Post by M***@gmail.com
, or the memory efficient variants <= and >= . They might give you
more ideas to solve your problems.
And as long as you are paying all this money for the
self-improvement course, have a look at compile options
defint32 and strictarr. Those won't hurt you any, either. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
M***@gmail.com
2008-04-06 12:19:01 UTC
Permalink
Thank you very much!

Continue reading on narkive:
Loading...