tags:

views:

52

answers:

1

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?

+4  A: 

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);
Jonas
voila! many thanks!
flyingcrab

related questions