Get supersets from cell array of doubles

4 visualizzazioni (ultimi 30 giorni)
Hau Kit Yong
Hau Kit Yong il 20 Gen 2021
Modificato: dpb il 21 Gen 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 Commento
dpb
dpb il 21 Gen 2021
Modificato: dpb il 21 Gen 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.

Accedi per commentare.

Risposta accettata

dpb
dpb il 21 Gen 2021
Modificato: dpb il 21 Gen 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.

Più risposte (0)

Categorie

Scopri di più su Data Type Identification in Help Center e File Exchange

Tag

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by