Check if (x,y) point is within 2d array of (x,y) entries. Where x is one column and y another
18 次查看(过去 30 天)
显示 更早的评论
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 个评论
Sathya Sri Chikoti
2020-11-4
x = 3;
y = 7;
a=[1 2 3 4; 5 6 7 8];
isPresent = any(ismember(a.', [x y], 'rows'));
回答(1 个)
Rishabh Mishra
2020-11-8
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!