Home > . > update_menu.m

update_menu

PURPOSE ^

'update_menu': find an input string in a menu, add it to the menu at the penultimate position if it does not exist

SYNOPSIS ^

function menu_str=update_menu(handle,strinput)

DESCRIPTION ^

'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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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)

Generated on Fri 13-Nov-2009 11:17:03 by m2html © 2003