# HG changeset patch # User Rik # Date 1361405507 28800 # Node ID c90c9623b20f297c1404f5f6ccc63f6b8c91216b # Parent 7cfb186592deb3afd2d7ee823a029187ab4aeba3 newplot.m: Return handle to created axes for Matlab compatibility (Bug #38146) * newplot.m: Return handle to created axes if nargout > 0. diff -r 7cfb186592de -r c90c9623b20f scripts/plot/newplot.m --- a/scripts/plot/newplot.m Sat Feb 16 22:06:59 2013 -0500 +++ b/scripts/plot/newplot.m Wed Feb 20 16:11:47 2013 -0800 @@ -17,13 +17,17 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} newplot () +## @deftypefn {Function File} {} newplot () +## @deftypefnx {Function File} {@var{h} =} newplot () ## Prepare graphics engine to produce a new plot. This function is ## called at the beginning of all high-level plotting functions. ## It is not normally required in user programs. +## +## The optional return value @var{h} is a graphics handle to the created +## axes (not figure). ## @end deftypefn -function newplot () +function h = newplot () if (nargin == 0) cf = gcf (); @@ -59,6 +63,9 @@ otherwise error ("newplot: unrecognized nextplot property for current axes"); endswitch + if (nargout > 0) + h = ca; + endif else print_usage (); endif @@ -70,7 +77,8 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! p = plot ([0, 1]); -%! newplot; +%! ha = newplot (); +%! assert (ha, gca); %! assert (isempty (get (gca, "children"))); %! unwind_protect_cleanup %! close (hf);