Cropping a range of Coordinates from a bigger data set

3 views (last 30 days)
I have an x-y coordinates data set measuring [0 2000 0 4000]. I wish to extract the coordinates in the range [500 1500 0 1000]. How do I do this? Thanks.

Accepted Answer

Image Analyst
Image Analyst on 1 Aug 2012
John: Thanks for the improved explanation. Try this:
% Generate some sample data.
xyCoords = 4000 * rand(50, 2)
% Now determine when x is in range.
x_in_range = xyCoords(:,1) >= 500 & xyCoords(:,1) <= 1500
% Now determine when y is in range.
y_in_range = xyCoords(:,2) >= 0 & xyCoords(:,2) <= 1000
% Now determine when both x and y are in range.
both_in_range = x_in_range & y_in_range;
% Now extract those rows where both are in range.
out = xyCoords(both_in_range, :)

More Answers (2)

Image Analyst
Image Analyst on 31 Jul 2012
I"m not sure what measuring [0 2000 0 4000]" means. This is very imprecisely worded. I'm guessing that you have a 1-dimensional array where you have the 2001 x coordinates first, followed by 4001 y coordinates. I'm not sure why you have more y coordinates than x coordinates though. If so, I'd do this:
index1 = 500;
index2 = 1500;
xCoordinates = xy(index1:index2);
index1 = 2001 + 1; % Index of the first y coordinate.
index2 = 2001+1000; % Index of the 1000th y coordinate.
yCoordinates = xy(index1:index2);
If you mean something different then you'd need to explain better what you want.
  1 Comment
John
John on 1 Aug 2012
The coordinates are the x-y positions of trees in a given area [minX=0 maxX=2000 minY=0 maxY=4000]. I wish to extract the coordinates of trees in [minX=500 maxX=1500 minY=0 maxY=1000]

Sign in to comment.


Walter Roberson
Walter Roberson on 1 Aug 2012
XY( XY(:,1) >= 500 & XY(:,1) <= 1500, XY(:,2) >= 0 & XY(:,2) <= 1000)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!