Mercurial > hg > octave-lyh
annotate scripts/general/deal.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 | be55736a0783 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1998, 2004, 2005, 2006, 2007 Ariel Tankus |
4818 | 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. | |
4818 | 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/>. | |
4818 | 18 |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{r1}, @var{r2}, @dots{}, @var{rn}] =} deal (@var{a}) |
6714 | 21 ## @deftypefnx {Function File} {[@var{r1}, @var{r2}, @dots{}, @var{rn}] =} deal (@var{a1}, @var{a2}, @dots{}, @var{an}) |
4818 | 22 ## |
23 ## Copy the input parameters into the corresponding output parameters. | |
24 ## If only one input parameter is supplied, its value is copied to each | |
25 ## of the outputs. | |
26 ## | |
27 ## For example, | |
28 ## | |
29 ## @example | |
30 ## [a, b, c] = deal (x, y, z); | |
31 ## @end example | |
32 ## | |
33 ## @noindent | |
34 ## is equivalent to | |
35 ## | |
36 ## @example | |
37 ## @group | |
38 ## a = x; | |
39 ## b = y; | |
40 ## c = z; | |
41 ## @end group | |
42 ## @end example | |
43 ## | |
44 ## @noindent | |
45 ## and | |
46 ## | |
47 ## @example | |
48 ## [a, b, c] = deal (x); | |
49 ## @end example | |
50 ## | |
51 ## @noindent | |
52 ## is equivalent to | |
53 ## | |
54 ## @example | |
55 ## a = b = c = x; | |
56 ## @end example | |
57 ## @end deftypefn | |
58 | |
59 ## Author: Ariel Tankus | |
60 ## Author: Paul Kienzle and Etienne Grossman | |
61 ## Created: 13.11.98 | |
62 ## Adapted-by: jwe | |
63 | |
64 function [varargout] = deal (varargin) | |
65 | |
66 if (nargin == 0) | |
6046 | 67 print_usage (); |
4819 | 68 elseif (nargin == 1 || nargin == nargout) |
4820 | 69 varargout(1:nargout) = varargin; |
4818 | 70 else |
71 error ("deal: nargin > 1 and nargin != nargout"); | |
72 endif | |
73 | |
74 endfunction | |
4819 | 75 |
76 %!test | |
77 %! [a,b]=deal(1,2); | |
78 %! assert(a,1); | |
79 %! assert(b,2); | |
80 %!test | |
81 %! [a,b]=deal(1); | |
82 %! assert(a,1); | |
83 %! assert(b,1); |