# HG changeset patch # User Ben Abbott # Date 1223597194 14400 # Node ID a2c7775603ee0e9d49031c4ea8b9d968db7f9198 # Parent 963f94ba4e2a998eb34b82451b4b879badfdc3dd clf.m: Improve Matlab compatibility. diff -r 963f94ba4e2a -r a2c7775603ee scripts/ChangeLog --- a/scripts/ChangeLog Wed Oct 08 14:31:59 2008 -0400 +++ b/scripts/ChangeLog Thu Oct 09 20:06:34 2008 -0400 @@ -1,3 +1,7 @@ +2008-10-09 Ben Abbott + + * plot/clf.m: Improve Matlab compatibility. + 2008-10-08 John W. Eaton * miscellaneous/fileparts.m: Handle "/file" properly. diff -r 963f94ba4e2a -r a2c7775603ee scripts/plot/clf.m --- a/scripts/plot/clf.m Wed Oct 08 14:31:59 2008 -0400 +++ b/scripts/plot/clf.m Thu Oct 09 20:06:34 2008 -0400 @@ -18,24 +18,63 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} clf () -## Clear the current figure. -## @seealso{close, delete} +## @deftypefnx {Function File} {} clf ("reset") +## @deftypefnx {Function File} {} clf (@var{hfig}) +## @deftypefnx {Function File} {} clf (@var{hfig}, "reset") +## @deftypefnx {Function File} address@hidden =} clf (@dots{}) +## Delete the children of the current figure with visible handles. +## If @var{hfig} is specified and is an figure object handle, operate on it +## instead of the current figure. If the optional argument @code{"reset"} +## is specified, also delete the figure's children with hidden handles. +## @seealso{cla, close, delete} ## @end deftypefn ## Author: jwe -function clf () +function clf (varargin) - if (nargin == 0) - cf = gcf (); - set (cf, "currentaxes", []); - for k = get (cf, "children") - if (ishandle (k)) - delete (k); - endif - endfor + if (nargin > 2) + print_usage (); + elseif (nargin > 1) + if (isfigure (varargin{1}) && + ischar (varargin{2}) && strcmpi (varargin{2}, "reset")) + oldfig = gcf; + hfig = varargin{1}; + do_reset = true; + else + print_usage (); + endif + elseif (nargin == 1) + if (isfigure (varargin{1})) + oldfig = gcf; + hfig = varargin{1}; + do_reset = false; + elseif (ischar (varargin{1}) && strcmpi (varargin{1}, "reset")) + hfig = gcf; + oldfig = hfig; + do_reset = true; + else + print_usage (); + endif else - print_usage (); + hfig = gcf; + oldfig = hfig; + do_reset = false; + end + + if (do_reset) + ## Select all the children. + hc = get (hfig, "children"); + ## FIXME - Matlab also resets the figure properties, except for + ## "position" and "units", to their defaults. + else + ## Select only the visible chilren. + hc = findobj (get (hfig, "children"), "flat", "visible", "on"); + ## Exclude the figure. + hc = setdiff (hc, hfig); endif + ## Delete the children. + delete (hc); + endfunction