# HG changeset patch # User Rik # Date 1380129810 25200 # Node ID 995decfed6cc58a968ffb5372b5e7b3e15f634ac # Parent 710309214e0d9a85250c18e093dd64a61ea8da44 guidata.m: Overhaul function to use modern Octave conventions. * scripts/plot/guidata.m: Match variable names in function header to documentation. Place input validation first. Add %!error input validation blocks. diff --git a/scripts/plot/guidata.m b/scripts/plot/guidata.m --- a/scripts/plot/guidata.m +++ b/scripts/plot/guidata.m @@ -25,38 +25,43 @@ ## figure handle then it's parent figure will be used for storage. ## ## @var{data} must be a single object which means it is usually preferable -## for it to be a data container such as a cell array or struct. +## for it to be a data container such as a cell array or struct so that +## additional data items can be added easily. ## ## @seealso{getappdata, setappdata, get, set, getpref, setpref} ## @end deftypefn ## Author: goffioul -function varargout = guidata (varargin) +function dataout = guidata (h, data) + + if (nargin < 1 || nargin > 2) + print_usage (); + endif - if (nargin == 1 || nargin == 2) - h = varargin{1}; - if (ishandle (h)) - h = ancestor (h, "figure"); - if (! isempty (h)) - if (nargin == 1) - varargout{1} = get (h, "__guidata__"); - else - data = varargin{2}; - set (h, "__guidata__", data); - if (nargout == 1) - varargout{1} = data; - endif - endif - else - error ("no ancestor figure found"); - endif - else - error ("invalid object handle"); + if (! ishandle (h)) + error ("guidata: H must be a valid object handle"); + endif + h = ancestor (h, "figure"); + if (isempty (h)) + error ("guidata: no ancestor figure of H found"); + endif + + if (nargin == 1) + dataout = get (h, "__guidata__"); + else + set (h, "__guidata__", data); + if (nargout == 1) + dataout = data; endif - else - print_usage (); endif endfunction + +%% Test input validation +%!error guidata () +%!error guidata (1,2,3) +%!error guidata ({1}) +%!error guidata (0) +