]> Creatis software - CreaPhase.git/blob - octave_packages/communications-1.1.1/@galois/reshape.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / communications-1.1.1 / @galois / reshape.m
1 ## Copyright (C) 2011 David Bateman
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Loadable Function} {} reshape (@var{a}, @var{m}, @var{n})
18 ## Return a matrix with @var{m} rows and @var{n} columns whose elements are
19 ## taken from the Galois array @var{a}.  To decide how to order the elements,
20 ## Octave pretends that the elements of a matrix are stored in column-major
21 ## order (like Fortran arrays are stored).
22 ## 
23 ## For example,
24 ## 
25 ## @example
26 ## reshape (gf([1, 2, 3, 4],3), 2, 2)
27 ## ans =
28 ## GF(2^3) array. Primitive Polynomial = D^3+D+1 (decimal 11)
29 ## 
30 ## Array elements = 
31 ## 
32 ##   1  3
33 ##   2  4
34 ## @end example
35 ## 
36 ## The @code{reshape} function is equivalent to
37 ## 
38 ## @example
39 ## @group
40 ## retval = gf(zeros (m, n), a.m, a.prim_poly);
41 ## retval (:) = a;
42 ## @end group
43 ## @end example
44 ## 
45 ## @noindent
46 ## but it is somewhat less cryptic to use @code{reshape} instead of the
47 ## colon operator. Note that the total number of elements in the original
48 ## matrix must match the total number of elements in the new matrix.
49 ## @end deftypefn
50 ## @seealso{`:'}
51
52 function varargout = reshape (varargin)
53   varargout = cell (1, max(1, nargout));
54   [varargout{:}] = greshape (varargin{:});
55 endfunction
56