代码之家  ›  专栏  ›  技术社区  ›  fika_fika

MATLAB cellfun()将contains()映射到单元格数组

  •  0
  • fika_fika  · 技术社区  · 7 年前
    a={'hello','world','friends'};
    

    我想看看单元格数组中的每个单词是否都包含字母“o”,如何使用 cellfun() 要在紧凑表达式中实现以下内容?

       b = [ contains(a(1),'o')  contains(a(2),'o')  contains(a(3),'o')]
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   sco1    7 年前

    你不需要 cellfun ,如果您阅读 the documentation ,则, contains 本机用于字符的单元格数组:

    a = {'hello', 'world', 'friends'};
    b = contains(a, 'o');
    

    返回:

    b =
    
      1×3 logical array
    
       1   1   0