function h=uicpush(hfig, p1,v1,p2,v2,p3,v3,p4,v4,p5,v5,p6,v6,p7,v7,p8,v8,p9,v9,p10,v10) %UICPUSH Cyclic pushbutton uicontrol tool. % % H=UICPUSH(HFIG, 'P1',V1,'P2',V2,P3,V3...) % % Where: % HFIG : The figure handle (default gcf) % Pn : Uicontrol property name (up to 10 parameters are allowed) % Vn : Uicontrol property value % H : The handle of the 'pushbutton' uicontrol object created % % % This function allow you to create in a single call a cyclic % pushbutton uicontrol. % % The list of strings is passed in the 'string' property and is % stored in the 'ButtonDownFcn' property. Therefore, the 'userdata' % property is not used. % % To read the current index value of the list use: % % val=get(H, 'value'); % % To read the current string of the list use: % % val=get(H, 'string'); % % % Four CYCLE mode can be specified using the 'max' property: % % 'max' == 0 No cycling % 'max' == 1 Cycle the list [1 2 3 1 2 3 1 2 3...] (default) % 'max' == 2 Go down the list and come back up [1 2 3 2 1 2 3...] % 'max' == 3 Go down only ones and stay there [1 2 3] % % Note: The callback is evaluated BEFORE the string is cycled. % % Example: % h=uicpush(gcf, 'string', '1111|22222|33333|4444|5555', 'max', 1) % % See also: UICONTROL, EDITLIST. % This function can be modified with the only restriction that the % next two lines have to be reteined. % Copyright (c) 1996 by Claudio Rivetti % claudio@alice.uoregon.edu % % Last version: October 8, 1996. % ENJOY IT! % % NORMAL=0 CLYCIC=1 TWOWAY=2 ONEWAY=3 max values if nargin > 21 error('Too many input arguments.'); end % Get the passed parameters if nargin > 0, if isstr(hfig) if (nargin)/2-fix((nargin)/2), error('Incorrect number of input arguments') else cmdstr=['hfig, p1,']; for i=2:(nargin)/2, cmdstr = [cmdstr,'v',num2str(i-1),',p',num2str(i),',']; end fig=gcf; end else if (nargin-1)/2-fix((nargin-1)/2), error('Incorrect number of input arguments') else cmdstr=''; for i=1:(nargin-1)/2, cmdstr = [cmdstr,'p',num2str(i),',v',num2str(i),',']; end end fig=hfig; end cmdstr(length(cmdstr))=' '; else fig=gcf; end h=uicontrol(fig, 'style', 'pushbutton'); eval(['set(h,',cmdstr,');']); % Set the starting value and string str=get(h, 'string'); v=get(h, 'value'); if vsize(str,1) v=1; end bdf='%'; for i=1:size(str,1) bdf=[bdf '|' deblank(str(i,:))]; end set(h, 'string', str(v,:), 'min', v, 'value', v, 'ButtonDownFcn', bdf); % Build the edit callback cbk1 = 'set(gco, ''value'', get(gco, ''min''));'; %Set the current value cbk2 = get(h, 'CallBack'); %The user callback cbk3 = ';setcpush(gco, get(gco, ''min''));'; %Scroll the string push_cbk=[cbk1 cbk2 cbk3]; set(h, 'CallBack', push_cbk); return