Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个x大小为 Nx2 的矩阵(包含 (x,y) 坐标)和一个c大小为 Px1 (P<=N) 的矩阵,其中包含我感兴趣的某些 x 坐标。例如:
x
c
x = [10 3; 21 9; 98 54; 4 30; 37 12]; c = [4 98];
我想获取元素的坐标c(在上述情况下[4 3])。我怎样才能做到这一点?我只找到了c一个 1x1 矩阵(即标量)的方法。
[4 3]
ismember可用于测试多个值的成员资格。您可以对 N×2 矩阵进行切片以仅搜索 x 坐标。
ismember
coords = [1 2; 3 4; 5 6; 7 8]; c = [3 7 99]; [v i] = ismember(c, coords(:, 1)); i = [2 4 0]
ic应包含其中的值显示为 x 坐标的索引,coords如果未找到该元素,则为 0。如果你有最新版本的 Matlab,你可以v用~.
i
coords
v
~