[英]How to remove all vectors from a cell B which belong to A or which are contained in one vector from A?
A = {[1 2 3 4],[22 55 78 84],[50 21 98 71],[10 15 16]};
B = {[2 4],[20 30 55],[16 15 10],[22 55 78]};
How to remove all vectors from a cell B which belong to A or which are contained in one vector from A? 如何从属于A的单元格B中删除所有向量或从A中包含在一个向量中的向量?
The desired result for my example 我的例子的理想结果
out = {[20 30 55]}
A one-liner: 单行:
out = B(~cellfun(@(y) any(cellfun(@(x) all(ismember(y,x)), A)), B));
The explanation of the code is just saying in other words what you asked for: the inner cellfun
detects if a vector of B
is completely contained by one of the vectors of A
, and the outer cellfun
assembles these results for all B
vectors. 代码的解释只是说,换句话说,你问什么:内
cellfun
检测是否向量B
完全由的载体之一包含A
,外cellfun
组装这些结果对于所有B
载体。 The resulting logical vector (the size of B
) is negated, because you want the vectors that are unique to B
, not the ones "embedded" in A
. 得到的逻辑向量(
B
的大小)被否定,因为你想要B
唯一向量,而不是A
“嵌入”的向量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.