view scripts/general/reshape.m @ 70:a5e8b7c9a3ad

[project @ 1993-08-30 14:32:55 by jwe]
author jwe
date Mon, 30 Aug 1993 14:32:55 +0000
parents b4df021f796c
children 16a24e76d6e0
line wrap: on
line source

function retval = reshape (a, m, n)

# usage: reshape (a, m, n)
#
# Form an m x n matrix from the elements of a (taken in Fortran's
# column major ordering).
#
# See also: `:', do_fortran_indexing

  if (nargin != 3)
    error ("usage: reshape (a, m, n)");
  else
    [nr, nc] = size (a);
    if (nr * nc == m * n)
      tmp = do_fortran_indexing;
      do_fortran_indexing = "true";
      retval = zeros (m, n);
      retval (:) = a;
      do_fortran_indexing = tmp;
    else
      error ("reshape: sizes must match");
    endif
  endif

endfunction