# HG changeset patch # User Ben Abbott # Date 1231747099 -3600 # Node ID dabbfac27a451415ecdb0b2818e3667a79eff553 # Parent 9e07dffc8a6032e57f949915cc8d639eaa70ed16 clf.m: Improve Matlab compatibility. diff -r 9e07dffc8a60 -r dabbfac27a45 scripts/ChangeLog --- a/scripts/ChangeLog Mon Jan 05 08:20:15 2009 +0100 +++ b/scripts/ChangeLog Mon Jan 12 08:58:19 2009 +0100 @@ -1,3 +1,7 @@ +2008-10-21 Ben Abbott + + * plot/clf.m: Improve Matlab compatibility. + 2008-10-16 David Bateman * plot/subplot.m: Allow for column vector of children for figure. diff -r 9e07dffc8a60 -r dabbfac27a45 scripts/plot/clf.m --- a/scripts/plot/clf.m Mon Jan 05 08:20:15 2009 +0100 +++ b/scripts/plot/clf.m Mon Jan 12 08:58:19 2009 +0100 @@ -18,24 +18,60 @@ ## -*- 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} {@var{hfig} =} 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, including the one with hidden handles. + hc = allchild (hfig); + reset (hfig) + else + ## Select only the chilren with visible handles. + hc = get (hfig, "children"); endif + ## Delete the children. + delete (hc); + endfunction