在结构字段中查找字符串的索引

find index of a string in a structure field

我有一个包含 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.

快到了。将 STRUCT.LAB 包裹在一个单元格中:

idx = find(strcmp({STRUCT.LAB},'INPUT'))