【问题标题】:How to find unique cells (with numbers NOT string) among cell array in Matlab如何在 Matlab 中的单元格数组中找到唯一的单元格(数字不是字符串)
【发布时间】:2013-05-30 17:45:08
【问题描述】:

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

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

我想要得到的结果是:

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

你有什么想法吗?

最好的问候 卡罗琳娜

【问题讨论】:

    标签: arrays matlab integer unique cell


    【解决方案1】:

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

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

    然后照常使用unique

    [C,ia] = unique(B)
    

    然后使用索引ia 指向唯一的单元格:

    A{ia}
    

    【讨论】:

      【解决方案2】:

      如果你写A如下:

      A={[1,3,4] [4,7] [1,3,4]; [3,6]  [4,7] []; [1,3,4]  [4,7] [4]};
      tmp = cellfun(@(x)(num2str(x)),A,'uniformoutput',false);
      unique(tmp);
      

      【讨论】:

        猜你喜欢
        • 2014-03-22
        • 1970-01-01
        • 2019-05-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多