Get supersets from cell array of doubles

3 次查看(过去 30 天)
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 个评论
dpb
dpb 2021-1-21
编辑:dpb 2021-1-21
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.

请先登录,再进行评论。

采纳的回答

dpb
dpb 2021-1-21
编辑:dpb 2021-1-21
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by