Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying uniques in a cell array

Tags:

matlab

cells

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?

like image 837
malangi Avatar asked Mar 06 '10 11:03

malangi


1 Answers

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);
like image 111
Jonas Avatar answered Sep 18 '22 10:09

Jonas