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

18 visualizaciones (últimos 30 días)
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 comentario
Sathya Sri Chikoti
Sathya Sri Chikoti el 4 de Nov. de 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'));

Iniciar sesión para comentar.

Respuestas (1)

Rishabh Mishra
Rishabh Mishra el 8 de Nov. de 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.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by