changelog shortlog tags changeset files revisions annotate raw

scripts/general/celldisp.m

changeset 9846: 1d90fc211872
parent:58604c45ca74
author: John W. Eaton <jwe@octave.org>
date: Sat Nov 21 21:44:51 2009 -0500 (33 hours ago)
permissions: -rw-r--r--
description: configure.ac: report freetype, fontconfig, and fltk cflags and libs info
1## Copyright (C) 2007, 2009 David Bateman
2##
3## This file is part of Octave.
4##
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.
9##
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.
14##
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/>.
18
19## -*- texinfo -*-
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}.
24## @seealso{disp}
25## @end deftypefn
26
27## This is ugly, but seems to be what matlab does..
28
29function celldisp (c, name)
30 if (nargin < 1 || nargin > 2)
31 print_usage ();
32 endif
33
34 if (! iscell (c))
35 error ("celldisp: argument must be a cell array");
36 endif
37
38 if (nargin == 1)
39 name = inputname (1);
40 endif
41
42 for i = 1: numel (c)
43 if (iscell (c{i}))
44 celldisp (c{i}, sprintf ("%s{%s}", name, indices (size (c), i)));
45 else
46 disp (sprintf ("%s{%s} = \n", name, indices (size (c), i)));
47 disp (c{i});
48 disp ("");
49 endif
50 endfor
51endfunction
52
53function s = indices (dv, i)
54 if (sum (dv != 1) > 1)
55 c = cell (size (dv));
56 [c{:}] = ind2sub (dv, i);
57 s = sprintf("%i,", c{:});
58 s(end) = [];
59 else
60 s = sprintf("%i", i);
61 endif
62endfunction