matlab - 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? -


for each vector of cell a, how find possible combinations of components not contained in vectors of cell b?

   = {[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}, possible combinations satisfy 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] contained in b{2}

[6 21] contained in b{1}

try this:

c = cell(1, numel(a)); 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 in c. run celldisp(c{1}) see result a{1}, example.

this code takes every vector in a , find possible combinations using nchoosek. then, checks if combination has values contained on vector of b, returning remaining combinations ont in b , putting them c.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

c# - MSDN OneNote Api: Navigate to never before opened page without opening a OneNote Application Window -