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)
Mostrar comentarios más antiguos
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
el 4 de Nov. de 2020
x = 3;
y = 7;
a=[1 2 3 4; 5 6 7 8];
isPresent = any(ismember(a.', [x y], 'rows'));
Respuestas (1)
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.
1 comentario
Ver también
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!