【问题标题】:How to find all cell arrays in a cell array, where the row count is bigger than a threshold?如何查找单元格数组中的所有单元格数组,其中行数大于阈值?
【发布时间】:2017-08-14 06:54:09
【问题描述】:

我有一组单元格BB 的每个元素都有不同的行号。如何仅访问 行数大于阈值B 元素?

我试过了:

A = B{cellfun('length', B) >= threshold};

这可以不用循环来完成吗?

【问题讨论】:

    标签: matlab indexing cell-array


    【解决方案1】:

    要么

    B(cellfun('length', B) >= threshold )
    

    B(cellfun(@(x) numel(x) >= threshold, B))
    

    应该可以。

    它们都计算内部元胞数组中的元素。


    如果你真的想要只有单元格,行数大于或等于阈值:

    B(cellfun('size', B, 1) >= threshold )
    

    B(cellfun(@(x) size(x, 1) >= threshold, B))
    

    示例

    arr_Row1Col1 = {1};
    arr_Row1Col2 = {1,2};
    arr_Row2Col1 = {1;2};
    arr_Row2Col2 = {1,2;3,4};
    
    threshold = 2;
    
    B = {arr_Row1Col1, arr_Row1Col2, arr_Row2Col1, arr_Row2Col2};
    
    % All inner-cells that have more than one element
    B(cellfun('length', B) >= threshold )
    
    % All inner-cells that have more than one row
    B(cellfun('size', B, 1) >= threshold )
    

    输出:

    ans = {1x2 cell}    {2x1 cell}    {2x2 cell}
    ans = {2x1 cell}    {2x2 cell}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      相关资源
      最近更新 更多