识别单元格阵列中的唯一性 [英] Identifying uniques in a cell array

查看:77
本文介绍了识别单元格阵列中的唯一性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a 45x2 cell in MATLAB, with the first column an arbitrarily sized matrix of doubles.

其中一些矩阵是重复的,而其他则不重复.我试图仅去除唯一的矩阵(但记录重复的次数),并保持第二列不变.

Some of these matrices are repeated, whilst others aren't. I'm attempting to strip out only the unique matrices (but recording the number of repeates), and keep the second column as is.

我已经尝试了许多方法(制表,历史等),但是由于细胞结构(我认为),它们都失败了.如果不逐一遍历每个人,该如何去做呢?

I've tried a number of things (tabulate, hist et al) but they all fail because of the cell structure (I think). How would one go about doing this, short of looping through each of them individually?

推荐答案

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

If you convert your matrices to strings, you can run unique on them:

%# 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);

这篇关于识别单元格阵列中的唯一性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆