我想在 Matlab GUI 的弹出菜单中获取所选项目的索引。为此,我在弹出回调函数下写了这个:
contents = cellstr(get(h0bject,'String'));
theItem = contents{get(h0bject,'Value')};
theindex = find(contents == theItem);
Matlab 返回:
Undefined function 'eq' for input arguments of type 'cell'
然后我写了
contents = cellstr(get(h0bject,'String'));
theItem = contents{get(h0bject,'Value')};
contents = cell2mat(contents):
theItem = str2num(theItem);
theindex = find(contents == theItem);
Matlab 返回
index = Empty matrix: 0-by-1
肯定theItem
是在contents
. 我怎样才能得到索引?我在哪里做错了?