Info

This question is closed. Reopen it to edit or answer.

To remove duplicated matrices in different cell...

1 view (last 30 days)
park minah
park minah on 14 Oct 2011
Closed: MATLAB Answer Bot on 20 Aug 2021
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.

Answers (1)

Andrei Bobrov
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
  2 Comments
park minah
park minah on 14 Oct 2011
andrei, thank you.
but I want not to use "cat".
because size of cell{1},cell{2} and cell{3} are actually very massive.
That is the reason why each matrix is stored by type of cell.
There is no way not to include "cat"?

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!