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
?
A = {[2 3 6 21],[66 4 2 7],[84 56 66 47 45]};
B = {[5 6 9 20 21],[7 85 14 2 3],[5 66 84 10 23 35 56],[5 6 87 14 21 29]};
For A{1}
, all possible combinations which satisfy the condition:
{[2 6],[2 21],[3 6],[3 21],[2 6 21],[2 3 6],[2 3 21],[3 6 21],[2 3 6 21]}
[2 3]
is contained in B{2}
[6 21]
is contained in B{1}
Try this:
C = cell(1, numel(A));
for ii = 1:numel(A)
aux = arrayfun(@(x) num2cell(nchoosek(A{ii}, x), 2)', 1:numel(A{ii}), 'Un', 0);
aux = [aux{:}];
C{ii} = aux(~cellfun(@(a) any(cellfun(@(b) all(ismember(a, b)), B)), aux));
end
The result will be in C
. Run celldisp(C{1})
to see the result for A{1}
, for example.
This code takes every vector in A
and find all possible combinations using nchoosek . Then, it checks if any combination has all values contained on any vector of B
, returning the remaining combinations which are ont in B
and putting them into C
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.