【问题标题】:How to compare cell content with a string in matlab?如何将单元格内容与matlab中的字符串进行比较?
【发布时间】:2014-04-24 08:35:44
【问题描述】:

我有一个元胞数组

>>D = {'Pop1','Pop2','Pop3','Pop4','Pop5','Pop6'}

现在我需要一个结果为[0 0 1 0 0 0]的数组

当我将 D 的元素与“Pop3”进行比较时。

我试过了

>> D == 'Pop3'
??? Undefined function or method 'eq' for input arguments of type 'cell'.

任何人都可以建议如何做到这一点?

【问题讨论】:

  • 使用ismember函数或strcmp函数

标签: string matlab cell


【解决方案1】:

你可以使用strcmp来做到这一点

>> D = {'Pop1','Pop2','Pop3','Pop4','Pop5','Pop6'}
D = 
    'Pop1'    'Pop2'    'Pop3'    'Pop4'    'Pop5'    'Pop6'
>> strcmp('Pop3', D)
ans =
     0     0     1     0     0     0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-11
    • 2019-04-15
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-21
    相关资源
    最近更新 更多