Re: Having trouble with code for data to image. [message #63977] |
Wed, 26 November 2008 05:09  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Nov 26, 7:37 am, "Jean H." <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
wrote:
> mbwel...@gmail.com wrote:
>> Hello,
>
>> I am running the code:
>
>> image = fltarr(nx,ny)
>> deltax = (xrange[1]-xrange[0])/float(nx)
>> deltay = (yrange[1]-yrange[0])/float(ny)
>> for i=0l,ndata-1 do $
>> image[(left[i]-xrange[0])/deltax:(right[i]-xrange[0])/deltax , $
>> (bottom[i]-yrange[0])/deltay:(top[i]-yrange[0])/deltay] =
>> magnitude
>> [i]
>
>> where: nx=ny=180
>> xrange= [-180,0]
>> yrange = [-90,90]
>> ndata = 32400 ( or180^2 or nx*ny)
>> eg left -180
>> right -179
>> top 90
>> bottom 89
>> magnitude 0.1648
>
>> and i get the error when I run the code:
>
>> % Subscript range values of the form low:high must be >= 0, < size,
>> with low <= high: IMAGE
>
>> I assume the problem is in the way that my data is ordered, and I have
>> tried switching lows and highs around, but to no avail. I would
>> imagine this is pretty simple to solve, but it is not clear to me
>> right now.
>
>> Any insight?
>
>> Thanks,
>
>> ~Matt
>
> Hi,
> with the data you provide, you are out of bounds...
> (bottom[i]-yrange[0])/deltay:(top[i]-yrange[0])/deltay] ==> 179:180
> ... 180 is out of bound. Remember that indexing is from 0 to n-1. You
> might want to throw a -1 in your indexes...
> As Chris has suggested it, print your indexes and be sure they are correct!
>
> Jean
That looks distinctly like code I suggested. ;-)
Yes, Jean is exactly right - there should be -1 in both the "top" and
"right" part of the indexing, i.e. replace the current line with:
image[(left[i]-xrange[0])/deltax:(right[i]-xrange[0])/deltax -1, $
(bottom[i]-yrange[0])/deltay:(top[i]-yrange[0])/deltay-1] =
magnitude[i]
Sorry about that!
-Jeremy.
|
|
|