如何在Matlab中的单元格数组中找到唯一的单元格(数字不是字符串)

Kar*_*ina 3 arrays matlab integer unique cell

我想问一下如何从像这样的单元格数组中找到唯一的单元格(整数不是字符串)(A的大小总是mxm):

A=({1,3,4} {4,7} {1,3,4};
    {3,6}  {4,7} {};
    {1,3,4}  {4,7} {4});
Run Code Online (Sandbox Code Playgroud)

我想要获得的结果是:

uniqueA = {1,3,4} {4,7} {3,6} {4}
Run Code Online (Sandbox Code Playgroud)

你有什么主意吗?

最好的问候Karolina

bla*_*bla 5

你可以将单元格转换为字符串fromat:

B = cellfun(@(x)(mat2str(x)),A,'uniformoutput',false);
Run Code Online (Sandbox Code Playgroud)

然后unique像往常一样使用:

[C,ia] = unique(B)
Run Code Online (Sandbox Code Playgroud)

然后使用索引ia指向具有以下内容的唯一单元格:

A{ia}
Run Code Online (Sandbox Code Playgroud)