1######################################################################## 2## 3## Copyright (C) 2012-2021 The Octave Project Developers 4## 5## See the file COPYRIGHT.md in the top-level directory of this 6## distribution or <https://octave.org/copyright/>. 7## 8## This file is part of Octave. 9## 10## Octave is free software: you can redistribute it and/or modify it 11## under the terms of the GNU General Public License as published by 12## the Free Software Foundation, either version 3 of the License, or 13## (at your option) any later version. 14## 15## Octave is distributed in the hope that it will be useful, but 16## WITHOUT ANY WARRANTY; without even the implied warranty of 17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18## GNU General Public License for more details. 19## 20## You should have received a copy of the GNU General Public License 21## along with Octave; see the file COPYING. If not, see 22## <https://www.gnu.org/licenses/>. 23## 24######################################################################## 25 26## -*- texinfo -*- 27## @deftypefn {} {@var{data} =} guidata (@var{h}) 28## @deftypefnx {} {} guidata (@var{h}, @var{data}) 29## Query or set user-custom GUI data. 30## 31## The GUI data is stored in the figure handle @var{h}. If @var{h} is not a 32## figure handle then it's parent figure will be used for storage. 33## 34## @var{data} must be a single object which means it is usually preferable 35## for it to be a data container such as a cell array or struct so that 36## additional data items can be added easily. 37## 38## @seealso{getappdata, setappdata, get, set, getpref, setpref} 39## @end deftypefn 40 41function dataout = guidata (h, data) 42 43 if (nargin < 1 || nargin > 2) 44 print_usage (); 45 endif 46 47 if (! ishghandle (h)) 48 error ("guidata: H must be a valid object handle"); 49 endif 50 h = ancestor (h, "figure"); 51 if (isempty (h)) 52 error ("guidata: no ancestor figure of H found"); 53 endif 54 55 if (nargin == 1) 56 dataout = get (h, "__guidata__"); 57 else 58 set (h, "__guidata__", data); 59 if (nargout == 1) 60 dataout = data; 61 endif 62 endif 63 64endfunction 65 66 67## Test input validation 68%!error guidata () 69%!error guidata (1,2,3) 70%!error <H must be a valid object handle> guidata ({1}) 71%!error <no ancestor figure of H found> guidata (0) 72