简体   繁体   English

查找B中包含但不在A - MATLAB中的列向量

[英]Find column vectors contained in B but not in A - MATLAB

I have matrix A of size 10x100 and matrix B with size 10x200 . 我有矩阵A大小的10x100和矩阵B与大小10x200

How to find the column vectors contained in B but not in A ? 如何找到包含在列向量B而不是在A ( A and B do not have the same number of columns) (A和B的列数不同)

to elaborate @Cheery's comment with an example. 用一个例子来详细说明@ Cheery的评论。

A=[1;4];
B=[1 2 4;4 5 6];
C=setdiff(B',A','rows')';

more details see http://www.mathworks.com/help/matlab/ref/setdiff.html 有关详细信息,请参阅http://www.mathworks.com/help/matlab/ref/setdiff.html

You can also use bsxfun here - 你也可以在这里使用bsxfun -

Bout = B(:,all(any(bsxfun(@ne,B,permute(A,[1 3 2])),1),3))

Sample run - 样品运行 -

A =
     2     2     2     2     2
     2     2     1     1     1
     1     1     2     1     3
B =
     3     2     3     2     1     2     2
     3     1     3     1     1     1     3
     2     3     1     2     1     2     3
Bout =
     3     3     1     2
     3     3     1     3
     2     1     1     3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM