0
我正在试图找到一种方法来查看字符串名称中是否包含字符串。在matlab中搜索字段名称中的一部分字符串
fieldName = 'OneTwoThree';
我想
findTwo
== true,如果fieldName
包含字符'Two'
某处串
有什么建议?
我正在试图找到一种方法来查看字符串名称中是否包含字符串。在matlab中搜索字段名称中的一部分字符串
fieldName = 'OneTwoThree';
我想
findTwo
== true,如果fieldName
包含字符'Two'
某处串
有什么建议?
您可以使用fieldnames
,然后strfind
。
a.OneTwoThree = 4; %// first field name
a.AnotherField = 'hello'; %// second example field name
测试所有的字段名称:
names = fieldnames(a); %// gives all field names
findTwo = ~isempty(strfind(names,'Two'));
只测试第一场:
names = fieldnames(a); %// gives all field names
findTwo = ~isempty(strfind(names{1},'Two'));
使用'strfind' ... – Daniel