Matlab-在矩阵中查找值
如何在矩阵B中找到包含A中所有值的行,并使用Matlab显示行的索引Matlab-在矩阵中查找值,matlab,matrix,Matlab,Matrix,如何在矩阵B中找到包含A中所有值的行,并使用Matlab显示行的索引 A= [2 5 6]; B=[1 2 4 9 10 15 27 30; 1 2 3 4 5 6 7 8; 1 2 3 5 6 9 22 101; 2 4 5 6 14 20 22 23] 感谢在3D- ind = find(all(any(bsxfun(@eq,B,permute(A,[1 3 2])),2),3)) ind = find(sum(reshape(any(bsxfun(@eq,B(
A= [2 5 6];
B=[1 2 4 9 10 15 27 30;
1 2 3 4 5 6 7 8;
1 2 3 5 6 9 22 101;
2 4 5 6 14 20 22 23]
感谢在3D
-
ind = find(all(any(bsxfun(@eq,B,permute(A,[1 3 2])),2),3))
ind = find(sum(reshape(any(bsxfun(@eq,B(:),A(:).'),2),size(B)),2)==numel(A))
再次使用bsxfun
,但将其保持在2D
-
ind = find(all(any(bsxfun(@eq,B,permute(A,[1 3 2])),2),3))
ind = find(sum(reshape(any(bsxfun(@eq,B(:),A(:).'),2),size(B)),2)==numel(A))
与-
来自-
再次使用统计和机器学习工具箱
-
[~,dists] = knnsearch(A(:),B(:))
ind = find(sum(reshape(dists==0,size(B)),2)==numel(A))
样本运行-
A =
2 5 6
B =
1 2 4 9 10 15 27 30
1 2 3 4 5 6 7 8
1 2 3 5 6 9 22 101
2 4 5 6 14 20 22 23
ind =
2
3
4
澄清一下:在您的示例中,您会得到第2、3和4行作为输出吗?或者
[2 5 6]
向量需要是连续的吗?现在一切都好了,下面的答案就是我想要的。Thanks@Emanuel考虑接受它,点击解决方案旁边的复选标记。阅读更多关于它的信息。如果我有三到四个矩阵在B中搜索并得到相似的索引?A=[2 5 6];C=[4 5 6];D=[8 9 10;2 9 19];B=[1 2 4 9 10 15 27 30;1 2 3 4 6 7 8;1 2 3 5 6 9 22 101;2 4 5 6 14 20 22 23]我该怎么做?