]> Creatis software - CreaPhase.git/blob - octave_packages/m/general/subsindex.m
update packages
[CreaPhase.git] / octave_packages / m / general / subsindex.m
1 ## Copyright (C) 2008-2012 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} {@var{idx} =} subsindex (@var{a})
21 ## Convert an object to an index vector.  When @var{a} is a class object
22 ## defined with a class constructor, then @code{subsindex} is the
23 ## overloading method that allows the conversion of this class object to
24 ## a valid indexing vector.  It is important to note that
25 ## @code{subsindex} must return a zero-based real integer vector of the
26 ## class "double".  For example, if the class constructor
27 ##
28 ## @example
29 ## @group
30 ## function b = myclass (a)
31 ##   b = class (struct ("a", a), "myclass");
32 ## endfunction
33 ## @end group
34 ## @end example
35 ##
36 ## @noindent
37 ## then the @code{subsindex} function
38 ##
39 ## @example
40 ## @group
41 ## function idx = subsindex (a)
42 ##   idx = double (a.a) - 1.0;
43 ## endfunction
44 ## @end group
45 ## @end example
46 ##
47 ## @noindent
48 ## can then be used as follows
49 ##
50 ## @example
51 ## @group
52 ## a = myclass (1:4);
53 ## b = 1:10;
54 ## b(a)
55 ## @result{} 1  2  3  4
56 ## @end group
57 ## @end example
58 ##
59 ## @seealso{class, subsref, subsasgn}
60 ## @end deftypefn
61
62 function idx = subsindex (a)
63   error ("subsindex: not defined for class \"%s\"", class(a));
64 endfunction
65