Effacer les filtres
Effacer les filtres

Get supersets from cell array of doubles

3 vues (au cours des 30 derniers jours)
Hau Kit Yong
Hau Kit Yong le 20 Jan 2021
Modifié(e) : dpb le 21 Jan 2021
I have a cell array of doubles, e.g.
C{1} = [1,2,3,4];
C{2} = [3,4,5,6,7,8];
C{3} = [2,3];
C{4} = [7,8,9,10];
C{5} = [1,2,6,7,8,9,10];
I want to find the indexes of arrays that are not fully contained within another array, so in this case, the code should return
[1,1,0,0,1]
I reckon some use of ismember is needed but I can't quite make out how.
  1 commentaire
dpb
dpb le 21 Jan 2021
Modifié(e) : dpb le 21 Jan 2021
I think you can only do that by testing each set with the combination of all other sets together.
ADDENDUM:
On thinking about it, I believe I'd be tempted to put the whole mess into a 2D array with the data in one column and the cell number in the second. Then a grouping variable could be used to operate by what is now cell.

Connectez-vous pour commenter.

Réponse acceptée

dpb
dpb le 21 Jan 2021
Modifié(e) : dpb le 21 Jan 2021
I misread the problem statement originally and the second idea didn't really help all that much. It's fairly straightforward, though...
res=false(numel(C));
for i=1:numel(C)
isOK=false;
for j=setdiff(1:numel(C),i)
isOK=isOK|all(ismember(C{i},C{j}));
end
res(i)=~isOK;
end
For the sample array above produces
>> res
res =
1×5 logical array
0 0 1 1 0
>> res=~res
res =
1×5 logical array
1 1 0 0 1
>>
before incorporating the not operator inside the loop over i ...did it that way to debug more easily. One could change the sense of the return from all at that point instead; your call.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Produits


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by