Matlab:如何在列表框中添加选定的项目?
问题描述:
我有两个列表框:Matlab:如何在列表框中添加选定的项目?
'unselectedchannellistbox'包含所有项目作为(nx1)单元格。 'selectedchannellistbox'为空。
'selectchannels'是一个按钮。
现在我想添加项目从'unselectedchannellistbox'到'selectectedchannellistbox'。但我不想删除或覆盖项目!
这是我的代码:
function selectchannels_Callback(hObject, eventdata, handles)
% Get selected item
listbox_strings = get(handles.unselectedchannellistbox,'String');
selected_value = get(handles.unselectedchannellistbox,'Value');
S = num2cell(selected_value);
for k = 1:length(S)
S(end+1) = {get(handles.unselectedchannellistbox,'Value')};
end
set(handles.selectedchannellistbox,'String',selected_value)
不幸的是,(结束+ 1),并获得加入一个新元素我的新单元阵列(S)(handles.unselectedchannellistbox, '值')不工作。
怎么回事?
非常感谢您的帮助!
Micha
答
最后我明白了!这对我完美的作品:
function selectchannels_Callback(hObject, eventdata, handles)
% Get selected item
listbox_strings = get(handles.unselectedchannellistbox,'String');
selected_value = get(handles.unselectedchannellistbox,'Value');
S = listbox_strings{selected_value};
set(handles.selectedchannellistbox,'String', ...
[get(handles.selectedchannellistbox, 'String'); {S}]);
非常感谢您的帮助!
请注明_doesn't work_。错误信息?错误的结果? ... – m7913d
这是错误的结果... Listbox2中的项目已被覆盖,所以总是只有一个条目。 –