识别单元格数组中的唯一元素

mal*_*ngi 6 matlab cells

我在MATLAB中有一个45x2的单元格,第一列是双倍的任意大小的矩阵.

其中一些矩阵是重复的,而另一些则不是.我试图去除唯一的矩阵(但记录重复次数),并按原样保留第二列.

我已经尝试了很多东西(制表,hist等),但由于细胞结构(我认为)它们都失败了.如何做到这一点,而不是单独循环每一个?

Jon*_*nas 11

如果将矩阵转换为字符串,则可以对它们运行唯一:

%# create a sample cell array
mc = {magic(3);magic(4);magic(4);magic(5);magic(3);magic(4)}

%# convert to strings
mcs = cellfun(@(x)(mat2str(x)),mc,'uniformoutput',false);

%# run unique
[uniqueCells,idxOfUnique,idxYouWant] = unique(mcs);
Run Code Online (Sandbox Code Playgroud)