Info
This question is closed. Reopen it to edit or answer.
To remove duplicated matrices in different cell...
1 view (last 30 days)
Show older comments
first, let me describe my situation for following example.
cell {1} = [1 2 3 4;5 6 7 8]
cell {2} = [1 1 1 1;1 2 3 4]
cell {3} = [5 6 7 8;2 2 2 2]
I would like to know whether [1 2 3 4] of cell 1 is in other cells. In this example, it exists in cell{2}.
similary, I alse wonder [5 6 7 8] of cell 1 exists in other cells in the same way.
In breif, I wonder there is a fuction searching for a specific matrix in each cell.
And if it is possible, I want to remove these matrices in each cell.
So, I want results as follows.
cell 1 = [1 2 3 4;5 6 7 8]
cell 2 = [1 1 1 1]
cell 3 = [2 2 2 2]
Is it possible? What should I do? help me, plz.
0 Comments
Answers (1)
Andrei Bobrov
on 14 Oct 2011
c = {[1 2 3 4;5 6 7 8];
[1 1 1 1;1 2 3 4];
[5 6 7 8;2 2 2 2]};
n = cellfun('size',c,1);
C = cat(1,c{:});
[~, b] = unique(C,'rows','first');
y =mat2cell(ismember((1:size(C,1))',b),n,1);
out = cellfun(@(x,y)x(y,:),c,y,'un',0)
add use loop for
n = numel(c);
for j1 = 1:n-1
for j2 = j1+1:n
c{j2} = c{j2}(~ismember(c{j2},c{j1},'rows'),:);
end
end
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!