Mercurial > hg > octave-lyh
annotate scripts/general/celldisp.m @ 11188:4cb1522e4d0f
Use function handle as input to cellfun,
rather than quoted function name or anonymous function wrapper.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Wed, 03 Nov 2010 17:20:56 -0700 |
parents | 9d1a14e12431 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 2007, 2009 David Bateman |
6869 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6869 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6869 | 18 |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {} celldisp (@var{c}, @var{name}) | |
9036
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
21 ## Recursively display the contents of a cell array. By default the values |
58604c45ca74
Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
22 ## are displayed with the name of the variable @var{c}. However, this name |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
23 ## can be replaced with the variable @var{name}. For example: |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
24 ## |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
25 ## @example |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
26 ## @group |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
27 ## c = @{1, 2, @{31, 32@}@}; |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
28 ## celldisp(c, "b") |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
29 ## @result{} |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
30 ## b@{1@} = |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
31 ## 1 |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
32 ## b@{2@} = |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
33 ## 2 |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
34 ## b@{3@}@{1@} = |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
35 ## 31 |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
36 ## b@{3@}@{2@} = |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
37 ## 32 |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
38 ## @end group |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
39 ## @end example |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
40 ## |
6869 | 41 ## @seealso{disp} |
42 ## @end deftypefn | |
43 | |
44 ## This is ugly, but seems to be what matlab does.. | |
45 | |
46 function celldisp (c, name) | |
47 if (nargin < 1 || nargin > 2) | |
48 print_usage (); | |
49 endif | |
50 | |
51 if (! iscell (c)) | |
52 error ("celldisp: argument must be a cell array"); | |
53 endif | |
54 | |
55 if (nargin == 1) | |
56 name = inputname (1); | |
57 endif | |
58 | |
59 for i = 1: numel (c) | |
60 if (iscell (c{i})) | |
61 celldisp (c{i}, sprintf ("%s{%s}", name, indices (size (c), i))); | |
62 else | |
63 disp (sprintf ("%s{%s} = \n", name, indices (size (c), i))); | |
64 disp (c{i}); | |
65 disp (""); | |
66 endif | |
67 endfor | |
68 endfunction | |
69 | |
70 function s = indices (dv, i) | |
71 if (sum (dv != 1) > 1) | |
72 c = cell (size (dv)); | |
73 [c{:}] = ind2sub (dv, i); | |
74 s = sprintf("%i,", c{:}); | |
75 s(end) = []; | |
76 else | |
77 s = sprintf("%i", i); | |
78 endif | |
79 endfunction | |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
80 |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
81 %!demo |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
82 %! c = {1, 2, {31, 32}}; |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9245
diff
changeset
|
83 %! celldisp(c, "b") |