Info

此问题已关闭。 请重新打开它进行编辑或回答。

To remove duplicated matrices in different cell...

2 次查看(过去 30 天)
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.

回答(1 个)

Andrei Bobrov
Andrei Bobrov 2011-10-14
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 个评论
park minah
park minah 2011-10-14
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"?

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by