Find index to x,y pairs

I have two vectors xEdges and yEdges which define positions in the x,y plane. In the example below, the lower left location value would be (20, 2). Given a vector list of locations, how can I find their indices within xEdges,yEdges? In the example below, the indices corresponding to the desired locations xFind,yFind would be ix = [ 2 4 4 6 ], iy = [ 2 6 8 9 ]. I need to use the indices to look up values of a matrix which has size nY,nX.
xEdges = 2:11 ; yEdges = 20:28 ; % Location vector
xFind = [ 3 5 5 7 ] ; yFind = [ 21 25 27 28 ] ; % x, y pairs

 Accepted Answer

[xtf ix] = ismember(xFind,xEdges);
[ytf iy] = ismember(yFind,yEdges);

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!