find unique values in nested cell array

I have a nx1 cell array, with each row containing another cell array of variable size. I would like to isolate unique values in each nested array, while still keeping the structure of the larger cell array.
Help would be greatly appreciated. Thanks!

 採用された回答

Star Strider
Star Strider 2016 年 6 月 21 日

0 投票

I’m not sure what you want.
This will give you the unique values amongst all the nested cells in your cell array:
C = {{randi(99, 1, 10)}; {randi(99, 1, 5)}; {randi(99, 1, 20)}};
C1 = [C{:}];
Cu = unique([C1{:}]);

4 件のコメント

PBB
PBB 2016 年 6 月 21 日
This does help me find unique values, but it gets rid of the overall structure of the cell array(and nested arrays). I didn't make that clear in my original question- sorry about that.
Star Strider
Star Strider 2016 年 6 月 21 日
This may be closer to what you want:
C = {{randi(9, 1, 10)}; {randi(9, 1, 5)}; {randi(9, 1, 20)}};
Cu = cellfun(@(x) unique(x{:}), C, 'UniformOutput',false)
celldisp(Cu) % Display Results (Optional)
It will give you the unique values in each nested cell.
PBB
PBB 2016 年 6 月 30 日
Works well, thanks!!
Star Strider
Star Strider 2016 年 6 月 30 日
My pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStructures についてさらに検索

質問済み:

PBB
2016 年 6 月 21 日

コメント済み:

2016 年 6 月 30 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by