1 ## Copyright (C) 2007-2012 David Bateman
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} celldisp (@var{c}, @var{name})
21 ## Recursively display the contents of a cell array. By default the values
22 ## are displayed with the name of the variable @var{c}. However, this name
23 ## can be replaced with the variable @var{name}. For example:
27 ## c = @{1, 2, @{31, 32@}@};
44 ## This is ugly, but seems to be what matlab does..
46 function celldisp (c, name)
47 if (nargin < 1 || nargin > 2)
52 error ("celldisp: argument must be a cell array");
61 celldisp (c{i}, sprintf ("%s{%s}", name, indices (size (c), i)));
63 disp (sprintf ("%s{%s} = \n", name, indices (size (c), i)));
70 function s = indices (dv, i)
71 if (sum (dv != 1) > 1)
73 [c{:}] = ind2sub (dv, i);
74 s = sprintf("%i,", c{:});
82 %! c = {1, 2, {31, 32}};
86 %!error celldisp ({}, "name", 1);