Search code examples
arraysmatlabintegeruniquecell

How to find unique cells (with numbers NOT string) among cell array in Matlab


I would like to ask how to find unique cells (with integer number NOT string) from cell array like this (size of A is always m x m):

A=({1,3,4} {4,7} {1,3,4};
    {3,6}  {4,7} {};
    {1,3,4}  {4,7} {4});

The results which I want to obtain is:

uniqueA = {1,3,4} {4,7} {3,6} {4}

Do you have any idea?

Best Regards Karolina


Solution

  • you can convert the cell to string fromat:

    B = cellfun(@(x)(mat2str(x)),A,'uniformoutput',false);
    

    Then use unique as usual:

    [C,ia] = unique(B)
    

    then use the index ia to point to unique cells with:

    A{ia}