From: jenya polyakova on
Dear everybody,
for my data I have 30713 stations (i.e. the size of my vector is 1x30713). When I do code below , I am left with 25703 stations, which is wrong: I still have to have 30713. Essentially, the code below divides region study area into equal size boxes of size 10x10. It then stores the indecies of original data into cell structure where each cell is box of size 10x10.
I am not sure where I went wrong. It is, I think, the border effect. If anybody could help me with it, it would great. It is very easy code....

% Define region of study
lon_e = -125.0
lon_w = -70.0
lat_s = 25.0
lat_n = 50.0
%-----------------------------------------------------------------------
% Define box size
box_x = 10
box_y = 10
%-----------------------------------------------------------------------
% create boxes.
cnt = 1;
for ix = lon_e:box_x:lon_w
x(cnt) = ix;
cnt = cnt+1;
end
cnt = 1;
for iy = lat_s:box_y:lat_n
y(cnt) = iy;
cnt = cnt+1;
end
%---------------------------------------------------------------------
% now we will find indecies of station which belong to the particular box
cnt = 1;
for i = 1 : (length(x)-1)
for j = 1 : (length(y)-1)
% note lon and lat are vectors of coordinates of our original data.
jdx = find(x(i) < = lon & lon<=x(i+1) & y(j) <= lat & lat<= y(j+1));
% store these indecies into structure
if length(jdx) > 0
index{cnt} = jdx;
cnt = cnt + 1;
end
end
end
From: Walter Roberson on
jenya polyakova wrote:
> Dear everybody,
> for my data I have 30713 stations (i.e. the size of my vector is
> 1x30713). When I do code below , I am left with 25703 stations, which is
> wrong: I still have to have 30713. Essentially, the code below divides
> region study area into equal size boxes of size 10x10. It then stores
> the indecies of original data into cell structure where each cell is box
> of size 10x10.
> I am not sure where I went wrong. It is, I think, the border effect. If
> anybody could help me with it, it would great. It is very easy code....
>
> % Define region of study
> lon_e = -125.0
> lon_w = -70.0
> lat_s = 25.0
> lat_n = 50.0
> %-----------------------------------------------------------------------
> % Define box size
> box_x = 10
> box_y = 10
> %-----------------------------------------------------------------------
> % create boxes.
> cnt = 1;
> for ix = lon_e:box_x:lon_w
> x(cnt) = ix;
> cnt = cnt+1;
> end
> cnt = 1;
> for iy = lat_s:box_y:lat_n
> y(cnt) = iy;
> cnt = cnt+1;
> end

Why not use

x = lon_e:box_e:lon_w;
y = lat_s:box_y:lat_n;

> %---------------------------------------------------------------------
> % now we will find indecies of station which belong to the particular box
> cnt = 1;
> for i = 1 : (length(x)-1)
> for j = 1 : (length(y)-1)
> % note lon and lat are vectors of coordinates of our original data.
> jdx = find(x(i) < = lon & lon<=x(i+1) & y(j) <= lat & lat<= y(j+1));

When you use equalities on both sides of the test, you count boundary values
in two boxes.


> % store these indecies into structure
> if length(jdx) > 0
> index{cnt} = jdx;
> cnt = cnt + 1;
> end

There: if a box is empty, you don't count it. If you are sure that none of the
boxes are empty, then you do not need to test the length.

By the way, isempty() is faster than checking the length > 0.

> end
> end
From: jenya polyakova on
Walter Roberson <roberson(a)hushmail.com> wrote in message <hsv41i$o8p$1(a)canopus.cc.umanitoba.ca>...
> jenya polyakova wrote:
> > Dear everybody,
> > for my data I have 30713 stations (i.e. the size of my vector is
> > 1x30713). When I do code below , I am left with 25703 stations, which is
> > wrong: I still have to have 30713. Essentially, the code below divides
> > region study area into equal size boxes of size 10x10. It then stores
> > the indecies of original data into cell structure where each cell is box
> > of size 10x10.
> > I am not sure where I went wrong. It is, I think, the border effect. If
> > anybody could help me with it, it would great. It is very easy code....
> >
> > % Define region of study
> > lon_e = -125.0
> > lon_w = -70.0
> > lat_s = 25.0
> > lat_n = 50.0
> > %-----------------------------------------------------------------------
> > % Define box size
> > box_x = 10
> > box_y = 10
> > %-----------------------------------------------------------------------
> > % create boxes.
> > cnt = 1;
> > for ix = lon_e:box_x:lon_w
> > x(cnt) = ix;
> > cnt = cnt+1;
> > end
> > cnt = 1;
> > for iy = lat_s:box_y:lat_n
> > y(cnt) = iy;
> > cnt = cnt+1;
> > end
>
> Why not use
>
> x = lon_e:box_e:lon_w;
> y = lat_s:box_y:lat_n;
>
> > %---------------------------------------------------------------------
> > % now we will find indecies of station which belong to the particular box
> > cnt = 1;
> > for i = 1 : (length(x)-1)
> > for j = 1 : (length(y)-1)
> > % note lon and lat are vectors of coordinates of our original data.
> > jdx = find(x(i) < = lon & lon<=x(i+1) & y(j) <= lat & lat<= y(j+1));
>
> When you use equalities on both sides of the test, you count boundary values
> in two boxes.
>
>
> > % store these indecies into structure
> > if length(jdx) > 0
> > index{cnt} = jdx;
> > cnt = cnt + 1;
> > end
>
> There: if a box is empty, you don't count it. If you are sure that none of the
> boxes are empty, then you do not need to test the length.
>
> By the way, isempty() is faster than checking the length > 0.
>
> > end
> > end

Hi, I am not sure I understand if box is empty there are not indecies in it. Yet, somewhere in this code I go from 30713 stations to 25703. The way I calculate the number of stations after I run this code is:
sum = 0
for i=1:length(index)
sum=sum+length(index{i})
end
sum = 25703. Any suggestions. Thank you for your other suggestions. I really appreciate it.
From: Roger Stafford on
"jenya polyakova" <jenya56(a)yahoo.com> wrote in message <hsv2qo$1sj$1(a)fred.mathworks.com>...
> Dear everybody,
> for my data I have 30713 stations (i.e. the size of my vector is 1x30713). When I do code below , I am left with 25703 stations, which is wrong: I still have to have 30713. Essentially, the code below divides region study area into equal size boxes of size 10x10. It then stores the indecies of original data into cell structure where each cell is box of size 10x10.
> I am not sure where I went wrong. It is, I think, the border effect. If anybody could help me with it, it would great. It is very easy code....
>
> % Define region of study
> lon_e = -125.0
> lon_w = -70.0
> lat_s = 25.0
> lat_n = 50.0
> %-----------------------------------------------------------------------
> % Define box size
> box_x = 10
> box_y = 10
> %-----------------------------------------------------------------------
> % create boxes.
> cnt = 1;
> for ix = lon_e:box_x:lon_w
> x(cnt) = ix;
> cnt = cnt+1;
> end
> cnt = 1;
> for iy = lat_s:box_y:lat_n
> y(cnt) = iy;
> cnt = cnt+1;
> end
> %---------------------------------------------------------------------
> % now we will find indecies of station which belong to the particular box
> cnt = 1;
> for i = 1 : (length(x)-1)
> for j = 1 : (length(y)-1)
> % note lon and lat are vectors of coordinates of our original data.
> jdx = find(x(i) < = lon & lon<=x(i+1) & y(j) <= lat & lat<= y(j+1));
> % store these indecies into structure
> if length(jdx) > 0
> index{cnt} = jdx;
> cnt = cnt + 1;
> end
> end
> end

When you write lon_e:box_x:lon_w, you get only

x = [-125,-115,-105,-95,-85,-75]

What about any stations with longitude between -75 and =70? They get left out of 'index'. Similarly latitudes between 45 and 50 are left out. Would that account for the discrepancy? You should set all those limits so they are sure to include anything present in the original station data.

Roger Stafford