Identifying uniques in a cell array

限于喜欢 提交于 2019-12-19 02:54:29

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/2392256/identifying-uniques-in-a-cell-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!