简体   繁体   English

如何从属于A的单元格B中删除所有向量或从A中包含在一个向量中的向量?

[英]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.

相关问题 对于单元格A的每个向量,如何查找单元格B的向量中不包含的所有可能组成部分的组合? - For each vector of the cell A, How to find all possible combinations of its components that are not contained in vectors of the cell B? 如何找到包含至少一个向量B的元素的单元格A的向量? - How to find the vectors of the cell A that contain at least one element of the vector B? 我有 2 个数据向量。 如何从一个向量中绘制另一个向量中的某些特定值的数据? - I have 2 vectors of data. How can I plot data from one vector for some specific values from the other vector? Matlab-如何使用循环从一个向量创建两个向量 - Matlab- how to creat two vectors from one vector using loop 矢量化从一个单独的矢量中减去多个矢量 - Vectorizing the subtraction of multiple vectors from one individual vector 如何从匹配另一个向量中值的矩阵中删除所有行? - How to remove all the rows from a matrix that match values in another vector? 从向量获得的值的总和 - summation of values which are obtained from a vector 如何从一个向量中删除一个向量的元素? - How do I remove the elements of one vector from another? 从向量中获取向量矩阵 - get matrix of vectors from a vector 从任意向量获取平均为零的向量 - get vector which's mean is zero from arbitrary vector
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM