Argon
Argon

Reputation: 435

MATLAB: Using the unique function on a cell array of cell arrays

I have a 1x2 cell array composed of two cells: a 1x3 cell and a 1x4 cell. In particular, for the cell array a, I have:

a =
  1×2 cell array
    {1×3 cell}    {1×4 cell}

a{1} =
  1×3 cell array
    'A2'    '*'    'A*'

a{2} =
  1×4 cell array
    'A*'    'B'    'AB'    '*'

I want to use unique on a so that I can get out a cell array consisting of *, A*, B, A2, and AB (in no particular order). However, unique only operates on a cell array of character vectors (e.g. unique(a{1}) and unique(a{2}) work, but unique({a}) does not). Any suggestions on how to get the desired result?

Upvotes: 1

Views: 496

Answers (1)

MrAzzaman
MrAzzaman

Reputation: 4768

You can do this as follows:

unique([a{:}]);

ans = 

    '*'    'A'    'A*'    'A2'    'AB'    'B'

Upvotes: 1

Related Questions