List box items
1 回表示 (過去 30 日間)
古いコメントを表示
How can i check if the new item which i want to add to list box if it is exist or not
i write this code but it is not working
[filename, pathname] = uigetfile( ...
{'*.m', 'All matlab-Files (*.m)'; ...
'*.*','All Files (*.*)'}, ...
'Select Matlab File');
file = fullfile(pathname,filename);
filename = filename(1:end-2);
currentItems = get(handles.listbox1, 'String');
if pathname == 0
return
else
for n = 1:length(newItems)
if filename == currentItems(n);
uiwait(msgbox('The algorithm you select are exist! Please selesct another.','Error','modal'));
[filename, pathname] = uigetfile( ...
{'*.m', 'All matlab-Files (*.m)'; ...
'*.*','All Files (*.*)'}, ...
'Select Matlab File');
file = fullfile(pathname,filename);
filename = filename(1:end-2);
end
end
end
currentItems{end+1} = filename;
set(handles.listbox1,'String',currentItems);
0 件のコメント
採用された回答
Image Analyst
2011 年 12 月 23 日
Try using strcmpi(filename, currentItems(n))>0 instead of "filename == currentItems(n);"
Also, you need to set a flag for whether you should add the name. Currently you call currentItems{end+1} = filename; regardless if it's on the list already or not.
0 件のコメント
その他の回答 (1 件)
Aldin
2011 年 12 月 23 日
All your Items which you have in listbox put in an array then with for loop check if your item for adding is in listbox For example if you have in listbox: 'Aldin' 'Amani' 'Image' 'Spike' put all these names in an array like this:
array = ['Aldin','Amani','Image','Spike'];
than check with for loop: (guess your name for adding in list box is 'Ricky'):
for i = 1:length(array)
if strcmp(array(i),'Ricky')
disp('Ricky is in listbox')
else
disp('Ricky is not in listbox');
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!