【问题标题】:MATLAB: how to find indices of cells which have length greater than threshold?MATLAB:如何找到长度大于阈值的单元格索引?
【发布时间】:2013-10-10 20:17:39
【问题描述】:

假设我有一个如下定义的元胞数组:

A = {[1:6],[1:4], [1:6],[1:4],[1:4],[1:6] };  

我想找到长度大于阈值的单元格的索引, 我认为这可能有效:

I = cellfun(@(x) find(length(A)>threshold), A, 'UniformOutput', false);

但它没有(它返回一个包含所有 1 的 1x6 单元格)

如果有人可以提供帮助,将不胜感激!

提前致谢,

没有

【问题讨论】:

    标签: arrays matlab cell


    【解决方案1】:

    你快到了:

    I = find(cellfun(@(x)(length(x)>threshold), A))
    

    您希望find 位于cellfun 之外。 cellfun 将返回一个逻辑数组,判断A 的元素是否大于threshold。您不需要 'UniformOutput', false 位,因为您为每个单元格返回一个布尔值,因此输出是统一的。

    最后你有length(A),但这是A 中的单元格数量,因为你实际上想要代码中x 给出的每个单元格中向量的长度

    例如

    A = {[1:6], [1:4], [1:6], [1:4], [1:4], [1:6]};  
    thresold = 5;
    I = find(cellfun(@(x)(length(x)>threshold), A))
    
    I =
    
       1   3   6
    

    【讨论】:

    • 感谢您的解释!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-18
    • 1970-01-01
    • 2017-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-20
    相关资源
    最近更新 更多