~ubuntu-branches/ubuntu/wily/octave-miscellaneous/wily

« back to all changes in this revision

Viewing changes to inst/zigzag.m

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot, Rafael Laboissiere, Sébastien Villemot
  • Date: 2012-10-17 13:40:55 UTC
  • mfrom: (1.2.1) (12 sid)
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: package-import@ubuntu.com-20121017134055-vatltexghy77fnv7
Tags: 1.2.0-1
[ Rafael Laboissiere ]
* Imported Upstream version 1.2.0
* Bump Standards-Version to 3.9.4 (no changes needed)
* Refresh for new upstream release
* Use Sébastien Villemot's @debian.org email address
* Remove obsolete DM-Upload-Allowed flag
* Add patch autoload-yes.patch
* Add copyright info for file lauchli.m (included in a Debian patch)
* Add patch partcnt-test-succeeds.patch
* Build-depends on octave-pkg-dev >= 1.0.3

[ Sébastien Villemot ]
* debian/control: fix versioned dependency on debhelper
* Add lintian override for false positive on hardening (fortify)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
## Copyright (C) 2006 Fredrik Bulow <fredrik.bulow@gmail.com>
2
2
##
3
 
## This program is free software; you can redistribute it and/or modify
4
 
## it under the terms of the GNU General Public License as published by
5
 
## the Free Software Foundation; either version 2 of the License, or
6
 
## (at your option) any later version.
7
 
##
8
 
## This program is distributed in the hope that it will be useful,
9
 
## but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
## GNU General Public License for more details.
12
 
##
13
 
## You should have received a copy of the GNU General Public License
14
 
## along with this program; If not, see <http://www.gnu.org/licenses/>.
15
 
##
 
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/>.
16
15
 
17
16
## -*- texinfo -*-
18
17
## @deftypefn {Function File} {} zigzag (@var{mtrx})
41
40
## @end deftypefn
42
41
## @seealso{zagzig}
43
42
 
44
 
## Author:   Fredrik Bulow <fredrik.bulow@gmail.com>
45
 
 
46
43
function rval = zigzag(mtrx)
47
 
  if nargin < 1
48
 
    error('usage: zigzag(matrix); see help zigzag');
49
 
  end
 
44
  if nargin != 1
 
45
    print_usage;
 
46
  endif
50
47
  n=size(mtrx);
51
48
  
52
49
  if(issquare(mtrx)) #Square matrix (quick case)
76
73
    for i = n(2)-1:-1:1-n(1)
77
74
      new = diag(mtrx,i);
78
75
      if(floor(i/2)==i/2) ##Even?
79
 
        rval=[rval new'];
 
76
        rval=[rval new'];
80
77
      else                ##Odd!
81
 
        rval=[rval new((1+length(new))-(1:length(new)))'];
 
78
        rval=[rval new((1+length(new))-(1:length(new)))'];
82
79
      endif
83
80
    endfor
84
81
  endif
85
82
endfunction
86
 
%!
 
83
 
87
84
%!assert(zigzag(reshape(1:9,3,3)),[1   2   4   7   5   3   6   8   9])
88
 
%!