【发布时间】:2020-08-27 06:16:26
【问题描述】:
我有一个包含 12 个字段的结构 STRUCT(1x70 结构)。第一个字段 LAB 包含每个单元格中的字符串(例如,“ab1”、“fj3”、“INPUT”、“OUTPUT”等)。我需要找到字符串'INPUT'的索引。
STRUCT = struct('LAB',{'ab1', 'fj3', 'INPUT', 'OUTPUT'},'fieldname2',{10,32,53,14})
我已尝试使用以下代码行,但每一行都不起作用。
idx = strfind(STRUCT.LAB, 'INPUT'); %Error using strfind Unrecognized parameter name 'INPUT'.
idx = ([STRUCT.LAB]=='INPUT') %Matrix dimensions must agree.
idx = find(strcmp([STRUCT.LAB], 'INPUT')) %ans: [] rather than 3.
【问题讨论】:
标签: string matlab indexing structure