'update_menu': find an input string in a menu, add it to the menu at the penultimate position if it does not exist ----------------------------------------------- function menu_str=update_menu(handle,strinput) OUTPUT: menu_str: new menu; cell of strings INPUT: handle: handle of the menu to modify (listbox uicontrol) strinput: char string to detect or add in the menu
0001 %'update_menu': find an input string in a menu, add it to the menu at the penultimate position if it does not exist 0002 %----------------------------------------------- 0003 % function menu_str=update_menu(handle,strinput) 0004 % 0005 % OUTPUT: 0006 % menu_str: new menu; cell of strings 0007 % 0008 % INPUT: 0009 % handle: handle of the menu to modify (listbox uicontrol) 0010 % strinput: char string to detect or add in the menu 0011 0012 function menu_str=update_menu(handle,strinput) 0013 menu_str=get(handle,'String'); 0014 nbmenu=length(menu_str); 0015 ichoice=0;%default 0016 for imenu=1:nbmenu 0017 if isequal(menu_str{imenu},strinput) 0018 ichoice=imenu; 0019 end 0020 end 0021 if ichoice==0%the input string does not exist in the menu 0022 menu_str{nbmenu+1}=menu_str{nbmenu};%shift the last item ('more...') 0023 menu_str{nbmenu}=strinput; 0024 set(handle,'String',menu_str) 0025 ichoice=nbmenu; 0026 end 0027 set(handle,'Value',ichoice)