Check if (x,y) point is within 2d array of (x,y) entries. Where x is one column and y another

35 views (last 30 days)
Is there a way to check if (x,y) points is within 2d array of (x,y) entries. Where x is one column and y another. Preferably I want a list of boolean variables with 1 if (x,y) point is present in that positon and zero otherwise
  1 Comment
Sathya Sri Chikoti
Sathya Sri Chikoti on 4 Nov 2020
Matlab function ismember can be used for this purpose. You could try the code below:
x = 3;
y = 7;
a=[1 2 3 4; 5 6 7 8];
isPresent = any(ismember(a.', [x y], 'rows'));

Sign in to comment.

Answers (1)

Rishabh Mishra
Rishabh Mishra on 8 Nov 2020
Hi,
I would like to point out that to create a matrix of points (x,y) you can use complex number. For example, consider the matrix defined below:
mat = [1+2i 3+i;
3+4i 1+2i];
The above matrix is used to store the cartesian pairs (1,2), (3,1), (3,4) and (1,2).
Let’s say you want check if point 1+2i is present in the matrix or not. You can use the code below:
mat = [1+2i 3+i;
3+4i 1+2i];
point = 1+2i;
check = [mat == point];
Check is Boolean matrix that lists out the positions in original matrix where the point 1+2i is present.
Feel free to revert for any clarifications or queries.
Hope this helps.

Categories

Find more on Matrices and Arrays 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!