Re: array subscripting problem [message #43416] |
Mon, 11 April 2005 08:11  |
Benjamin Luethi
Messages: 22 Registered: December 2004
|
Junior Member |
|
|
Hi Martin,
You could also extract a 3x3 sub-array first and then do the comparisons
on it. This way you don't need any if checks at all:
s = Size(data, /Dimensions)
subarray=data[ ((i-1)>0):((i+1)<(s[0]-1)), ((j-1)>0):((j+1)<(s[1]-1)), k ]
f=f+total(ABS(cd-subarray) LE mg)-1
Notice that the subarray is not 3x3 if i or j are at the border.
Also notice the -1 in the third line: it's because the [i,j]-element is
always part of the subarray and counts as well.
Ben
On 11 Apr 2005 06:00:14 -0700, Martin Doyle <m.doyle@uea.ac.uk> wrote:
> Hi Guys,
>
> I've got a gridded dataset and I'm searching the grid trying to find
> those points which have a certain value. Once I've found this point, I
> want to check all points around it to see if they have the same value
> plus a little bit. This is what I've come up with:
>
> If (data(i,j,k) GE p) THEN begin
>
> cd = data(i,j,k)
>
> If(ABS(cd-data[i-1,j-1,k]) LE mg) then f = f+1
> If(ABS(cd-data[i, j-1,k]) LE mg) then f = f+1
> If(ABS(cd-data[i+1,j-1,k]) LE mg) then f = f+1
> If(ABS(cd-data[i-1,j, k]) LE mg) then f = f+1
> If(ABS(cd-data[i+1,j, k]) LE mg) then f = f+1
> If(ABS(cd-data[i-1,j+1,k]) LE mg) then f = f+1
> If(ABS(cd-data[i, j+1,k]) LE mg) then f = f+1
> If(ABS(cd-data[i+1,j+1,k]) LE mg) then f = f+1
>
> endif
>
> However, array subscripting with negative numbers isn't allowed by
> IDL.
>
> Has anyone any ideas how I might get around this?
>
> Many thanks!
>
> All the best
> Martin
--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
|
|
|