Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > b38d2da330d1936e5ab1307c039c4941 > files > 432

octave-doc-3.6.4-3.mga4.noarch.rpm

<html lang="en">
<head>
<title>Rearranging Matrices - GNU Octave</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Octave">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Matrix-Manipulation.html#Matrix-Manipulation" title="Matrix Manipulation">
<link rel="prev" href="Finding-Elements-and-Checking-Conditions.html#Finding-Elements-and-Checking-Conditions" title="Finding Elements and Checking Conditions">
<link rel="next" href="Special-Utility-Matrices.html#Special-Utility-Matrices" title="Special Utility Matrices">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Rearranging-Matrices"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Special-Utility-Matrices.html#Special-Utility-Matrices">Special Utility Matrices</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Finding-Elements-and-Checking-Conditions.html#Finding-Elements-and-Checking-Conditions">Finding Elements and Checking Conditions</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Matrix-Manipulation.html#Matrix-Manipulation">Matrix Manipulation</a>
<hr>
</div>

<h3 class="section">16.2 Rearranging Matrices</h3>

<!-- fliplr scripts/general/fliplr.m -->
<p><a name="doc_002dfliplr"></a>

<div class="defun">
&mdash; Function File:  <b>fliplr</b> (<var>x</var>)<var><a name="index-fliplr-1626"></a></var><br>
<blockquote><p>Return a copy of <var>x</var> with the order of the columns reversed.  In
other words, <var>x</var> is flipped left-to-right about a vertical axis.  For
example:

     <pre class="example">          fliplr ([1, 2; 3, 4])
               &rArr;  2  1
                   4  3
</pre>
        <p>Note that <code>fliplr</code> only works with 2-D arrays.  To flip N-D arrays
use <code>flipdim</code> instead. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dflipud.html#doc_002dflipud">flipud</a>, <a href="doc_002dflipdim.html#doc_002dflipdim">flipdim</a>, <a href="doc_002drot90.html#doc_002drot90">rot90</a>, <a href="doc_002drotdim.html#doc_002drotdim">rotdim</a>. 
</p></blockquote></div>

<!-- flipud scripts/general/flipud.m -->
   <p><a name="doc_002dflipud"></a>

<div class="defun">
&mdash; Function File:  <b>flipud</b> (<var>x</var>)<var><a name="index-flipud-1627"></a></var><br>
<blockquote><p>Return a copy of <var>x</var> with the order of the rows reversed.  In
other words, <var>x</var> is flipped upside-down about a horizontal axis.  For
example:

     <pre class="example">          flipud ([1, 2; 3, 4])
               &rArr;  3  4
                   1  2
</pre>
        <p>Note that <code>flipud</code> only works with 2-D arrays.  To flip N-D arrays
use <code>flipdim</code> instead. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dfliplr.html#doc_002dfliplr">fliplr</a>, <a href="doc_002dflipdim.html#doc_002dflipdim">flipdim</a>, <a href="doc_002drot90.html#doc_002drot90">rot90</a>, <a href="doc_002drotdim.html#doc_002drotdim">rotdim</a>. 
</p></blockquote></div>

<!-- flipdim scripts/general/flipdim.m -->
   <p><a name="doc_002dflipdim"></a>

<div class="defun">
&mdash; Function File:  <b>flipdim</b> (<var>x</var>)<var><a name="index-flipdim-1628"></a></var><br>
&mdash; Function File:  <b>flipdim</b> (<var>x, dim</var>)<var><a name="index-flipdim-1629"></a></var><br>
<blockquote><p>Return a copy of <var>x</var> flipped about the dimension <var>dim</var>. 
<var>dim</var> defaults to the first non-singleton dimension. 
For example:

     <pre class="example">          flipdim ([1, 2; 3, 4], 2)
                &rArr;  2  1
                    4  3
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dfliplr.html#doc_002dfliplr">fliplr</a>, <a href="doc_002dflipud.html#doc_002dflipud">flipud</a>, <a href="doc_002drot90.html#doc_002drot90">rot90</a>, <a href="doc_002drotdim.html#doc_002drotdim">rotdim</a>. 
</p></blockquote></div>

<!-- rot90 scripts/general/rot90.m -->
   <p><a name="doc_002drot90"></a>

<div class="defun">
&mdash; Function File:  <b>rot90</b> (<var>A</var>)<var><a name="index-rot90-1630"></a></var><br>
&mdash; Function File:  <b>rot90</b> (<var>A, k</var>)<var><a name="index-rot90-1631"></a></var><br>
<blockquote><p>Return a copy of <var>A</var> with the elements rotated counterclockwise in
90-degree increments.  The second argument is optional, and specifies
how many 90-degree rotations are to be applied (the default value is 1). 
Negative values of <var>k</var> rotate the matrix in a clockwise direction. 
For example,

     <pre class="example">          rot90 ([1, 2; 3, 4], -1)
              &rArr;  3  1
                  4  2
</pre>
        <p class="noindent">rotates the given matrix clockwise by 90 degrees.  The following are all
equivalent statements:

     <pre class="example">          rot90 ([1, 2; 3, 4], -1)
          rot90 ([1, 2; 3, 4], 3)
          rot90 ([1, 2; 3, 4], 7)
</pre>
        <p>Note that <code>rot90</code> only works with 2-D arrays.  To rotate N-D arrays
use <code>rotdim</code> instead. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002drotdim.html#doc_002drotdim">rotdim</a>, <a href="doc_002dflipud.html#doc_002dflipud">flipud</a>, <a href="doc_002dfliplr.html#doc_002dfliplr">fliplr</a>, <a href="doc_002dflipdim.html#doc_002dflipdim">flipdim</a>. 
</p></blockquote></div>

<!-- rotdim scripts/general/rotdim.m -->
   <p><a name="doc_002drotdim"></a>

<div class="defun">
&mdash; Function File:  <b>rotdim</b> (<var>x</var>)<var><a name="index-rotdim-1632"></a></var><br>
&mdash; Function File:  <b>rotdim</b> (<var>x, n</var>)<var><a name="index-rotdim-1633"></a></var><br>
&mdash; Function File:  <b>rotdim</b> (<var>x, n, plane</var>)<var><a name="index-rotdim-1634"></a></var><br>
<blockquote><p>Return a copy of <var>x</var> with the elements rotated counterclockwise in
90-degree increments. 
The second argument <var>n</var> is optional, and specifies how many 90-degree
rotations are to be applied (the default value is 1). 
The third argument is also optional and defines the plane of the
rotation.  If present, <var>plane</var> is a two element vector containing two
different valid dimensions of the matrix.  When <var>plane</var> is not given
the first two non-singleton dimensions are used.

        <p>Negative values of <var>n</var> rotate the matrix in a clockwise direction. 
For example,

     <pre class="example">          rotdim ([1, 2; 3, 4], -1, [1, 2])
               &rArr;  3  1
                   4  2
</pre>
        <p class="noindent">rotates the given matrix clockwise by 90 degrees.  The following are all
equivalent statements:

     <pre class="example">          rotdim ([1, 2; 3, 4], -1, [1, 2])
          rotdim ([1, 2; 3, 4], 3, [1, 2])
          rotdim ([1, 2; 3, 4], 7, [1, 2])
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002drot90.html#doc_002drot90">rot90</a>, <a href="doc_002dflipud.html#doc_002dflipud">flipud</a>, <a href="doc_002dfliplr.html#doc_002dfliplr">fliplr</a>, <a href="doc_002dflipdim.html#doc_002dflipdim">flipdim</a>. 
</p></blockquote></div>

<!-- cat src/data.cc -->
   <p><a name="doc_002dcat"></a>

<div class="defun">
&mdash; Built-in Function:  <b>cat</b> (<var>dim, array1, array2, <small class="dots">...</small>, arrayN</var>)<var><a name="index-cat-1635"></a></var><br>
<blockquote><p>Return the concatenation of N-D array objects, <var>array1</var>,
<var>array2</var>, <small class="dots">...</small>, <var>arrayN</var> along dimension <var>dim</var>.

     <pre class="example">          A = ones (2, 2);
          B = zeros (2, 2);
          cat (2, A, B)
              &rArr; 1 1 0 0
                 1 1 0 0
</pre>
        <p>Alternatively, we can concatenate <var>A</var> and <var>B</var> along the
second dimension the following way:

     <pre class="example">          [A, B].
</pre>
        <p><var>dim</var> can be larger than the dimensions of the N-D array objects
and the result will thus have <var>dim</var> dimensions as the
following example shows:

     <pre class="example">          cat (4, ones (2, 2), zeros (2, 2))
              &rArr; ans =
          
                 ans(:,:,1,1) =
          
                   1 1
                   1 1
          
                 ans(:,:,1,2) =
                   0 0
                   0 0
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dhorzcat.html#doc_002dhorzcat">horzcat</a>, <a href="doc_002dvertcat.html#doc_002dvertcat">vertcat</a>. 
</p></blockquote></div>

<!-- horzcat src/data.cc -->
   <p><a name="doc_002dhorzcat"></a>

<div class="defun">
&mdash; Built-in Function:  <b>horzcat</b> (<var>array1, array2, <small class="dots">...</small>, arrayN</var>)<var><a name="index-horzcat-1636"></a></var><br>
<blockquote><p>Return the horizontal concatenation of N-D array objects, <var>array1</var>,
<var>array2</var>, <small class="dots">...</small>, <var>arrayN</var> along dimension 2.

        <p>Arrays may also be concatenated horizontally using the syntax for creating
new matrices.  For example:

     <pre class="example">          <var>hcat</var> = [ <var>array1</var>, <var>array2</var>, ... ];
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dcat.html#doc_002dcat">cat</a>, <a href="doc_002dvertcat.html#doc_002dvertcat">vertcat</a>. 
</p></blockquote></div>

<!-- vertcat src/data.cc -->
   <p><a name="doc_002dvertcat"></a>

<div class="defun">
&mdash; Built-in Function:  <b>vertcat</b> (<var>array1, array2, <small class="dots">...</small>, arrayN</var>)<var><a name="index-vertcat-1637"></a></var><br>
<blockquote><p>Return the vertical concatenation of N-D array objects, <var>array1</var>,
<var>array2</var>, <small class="dots">...</small>, <var>arrayN</var> along dimension 1.

        <p>Arrays may also be concatenated vertically using the syntax for creating
new matrices.  For example:

     <pre class="example">          <var>vcat</var> = [ <var>array1</var>; <var>array2</var>; ... ];
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dcat.html#doc_002dcat">cat</a>, <a href="doc_002dhorzcat.html#doc_002dhorzcat">horzcat</a>. 
</p></blockquote></div>

<!-- permute src/data.cc -->
   <p><a name="doc_002dpermute"></a>

<div class="defun">
&mdash; Built-in Function:  <b>permute</b> (<var>A, perm</var>)<var><a name="index-permute-1638"></a></var><br>
<blockquote><p>Return the generalized transpose for an N-D array object <var>A</var>. 
The permutation vector <var>perm</var> must contain the elements
<code>1:ndims(A)</code> (in any order, but each element must appear only once). 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dipermute.html#doc_002dipermute">ipermute</a>. 
</p></blockquote></div>

<!-- ipermute src/data.cc -->
   <p><a name="doc_002dipermute"></a>

<div class="defun">
&mdash; Built-in Function:  <b>ipermute</b> (<var>A, iperm</var>)<var><a name="index-ipermute-1639"></a></var><br>
<blockquote><p>The inverse of the <code>permute</code> function.  The expression

     <pre class="example">          ipermute (permute (A, perm), perm)
</pre>
        <p class="noindent">returns the original array <var>A</var>. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dpermute.html#doc_002dpermute">permute</a>. 
</p></blockquote></div>

<!-- reshape src/data.cc -->
   <p><a name="doc_002dreshape"></a>

<div class="defun">
&mdash; Built-in Function:  <b>reshape</b> (<var>A, m, n, <small class="dots">...</small></var>)<var><a name="index-reshape-1640"></a></var><br>
&mdash; Built-in Function:  <b>reshape</b> (<var>A, </var>[<var>m n <small class="dots">...</small></var>])<var><a name="index-reshape-1641"></a></var><br>
&mdash; Built-in Function:  <b>reshape</b> (<var>A, <small class="dots">...</small>, </var>[]<var>, <small class="dots">...</small></var>)<var><a name="index-reshape-1642"></a></var><br>
&mdash; Built-in Function:  <b>reshape</b> (<var>A, size</var>)<var><a name="index-reshape-1643"></a></var><br>
<blockquote><p>Return a matrix with the specified dimensions (<var>m</var>, <var>n</var>, <small class="dots">...</small>)
whose elements are taken from the matrix <var>A</var>.  The elements of the
matrix are accessed in column-major order (like Fortran arrays are stored).

        <p>The following code demonstrates reshaping a 1x4 row vector into a 2x2 square
matrix.

     <pre class="example">          reshape ([1, 2, 3, 4], 2, 2)
               &rArr;  1  3
                   2  4
</pre>
        <p class="noindent">Note that the total number of elements in the original
matrix (<code>prod (size (</code><var>A</var><code>))</code>) must match the total number of elements
in the new matrix (<code>prod ([</code><var>m</var> <var>n</var><code> ...])</code>).

        <p>A single dimension of the return matrix may be left unspecified and Octave
will determine its size automatically.  An empty matrix ([]) is used to flag
the unspecified dimension. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dresize.html#doc_002dresize">resize</a>. 
</p></blockquote></div>

<!-- resize src/data.cc -->
   <p><a name="doc_002dresize"></a>

<div class="defun">
&mdash; Built-in Function:  <b>resize</b> (<var>x, m</var>)<var><a name="index-resize-1644"></a></var><br>
&mdash; Built-in Function:  <b>resize</b> (<var>x, m, n, <small class="dots">...</small></var>)<var><a name="index-resize-1645"></a></var><br>
&mdash; Built-in Function:  <b>resize</b> (<var>x, </var>[<var>m n <small class="dots">...</small></var>])<var><a name="index-resize-1646"></a></var><br>
<blockquote><p>Resize <var>x</var> cutting off elements as necessary.

        <p>In the result, element with certain indices is equal to the corresponding
element of <var>x</var> if the indices are within the bounds of <var>x</var>;
otherwise, the element is set to zero.

        <p>In other words, the statement

     <pre class="example">            y = resize (x, dv);
</pre>
        <p class="noindent">is equivalent to the following code:

     <pre class="example">            y = zeros (dv, class (x));
            sz = min (dv, size (x));
            for i = 1:length (sz), idx{i} = 1:sz(i); endfor
            y(idx{:}) = x(idx{:});
</pre>
        <p class="noindent">but is performed more efficiently.

        <p>If only <var>m</var> is supplied, and it is a scalar, the dimension of the
result is <var>m</var>-by-<var>m</var>. 
If <var>m</var>, <var>n</var>, <small class="dots">...</small> are all scalars, then the dimensions of
the result are <var>m</var>-by-<var>n</var>-by-<small class="dots">...</small>. 
If given a vector as input, then the
dimensions of the result are given by the elements of that vector.

        <p>An object can be resized to more dimensions than it has;
in such case the missing dimensions are assumed to be 1. 
Resizing an object to fewer dimensions is not possible. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dreshape.html#doc_002dreshape">reshape</a>, <a href="doc_002dpostpad.html#doc_002dpostpad">postpad</a>. 
</p></blockquote></div>

<!-- circshift scripts/general/circshift.m -->
   <p><a name="doc_002dcircshift"></a>

<div class="defun">
&mdash; Function File: <var>y</var> = <b>circshift</b> (<var>x, n</var>)<var><a name="index-circshift-1647"></a></var><br>
<blockquote><p>Circularly shift the values of the array <var>x</var>.  <var>n</var> must be
a vector of integers no longer than the number of dimensions in
<var>x</var>.  The values of <var>n</var> can be either positive or negative,
which determines the direction in which the values or <var>x</var> are
shifted.  If an element of <var>n</var> is zero, then the corresponding
dimension of <var>x</var> will not be shifted.  For example:

     <pre class="example">          x = [1, 2, 3; 4, 5, 6; 7, 8, 9];
          circshift (x, 1)
          &rArr;  7, 8, 9
              1, 2, 3
              4, 5, 6
          circshift (x, -2)
          &rArr;  7, 8, 9
              1, 2, 3
              4, 5, 6
          circshift (x, [0,1])
          &rArr;  3, 1, 2
              6, 4, 5
              9, 7, 8
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> permute, ipermute, shiftdim. 
</p></blockquote></div>

<!-- shift scripts/general/shift.m -->
   <p><a name="doc_002dshift"></a>

<div class="defun">
&mdash; Function File:  <b>shift</b> (<var>x, b</var>)<var><a name="index-shift-1648"></a></var><br>
&mdash; Function File:  <b>shift</b> (<var>x, b, dim</var>)<var><a name="index-shift-1649"></a></var><br>
<blockquote><p>If <var>x</var> is a vector, perform a circular shift of length <var>b</var> of
the elements of <var>x</var>.

        <p>If <var>x</var> is a matrix, do the same for each column of <var>x</var>. 
If the optional <var>dim</var> argument is given, operate along this
dimension. 
</p></blockquote></div>

<!-- shiftdim scripts/general/shiftdim.m -->
   <p><a name="doc_002dshiftdim"></a>

<div class="defun">
&mdash; Function File: <var>y</var> = <b>shiftdim</b> (<var>x, n</var>)<var><a name="index-shiftdim-1650"></a></var><br>
&mdash; Function File: [<var>y</var>, <var>ns</var>] = <b>shiftdim</b> (<var>x</var>)<var><a name="index-shiftdim-1651"></a></var><br>
<blockquote><p>Shift the dimensions of <var>x</var> by <var>n</var>, where <var>n</var> must be
an integer scalar.  When <var>n</var> is positive, the dimensions of
<var>x</var> are shifted to the left, with the leading dimensions
circulated to the end.  If <var>n</var> is negative, then the dimensions
of <var>x</var> are shifted to the right, with <var>n</var> leading singleton
dimensions added.

        <p>Called with a single argument, <code>shiftdim</code>, removes the leading
singleton dimensions, returning the number of dimensions removed
in the second output argument <var>ns</var>.

        <p>For example:

     <pre class="example">          x = ones (1, 2, 3);
          size (shiftdim (x, -1))
             &rArr; [1, 1, 2, 3]
          size (shiftdim (x, 1))
             &rArr; [2, 3]
          [b, ns] = shiftdim (x)
             &rArr; b = [1, 1, 1; 1, 1, 1]
             &rArr; ns = 1
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> reshape, permute, ipermute, circshift, squeeze. 
</p></blockquote></div>

<!-- sort src/data.cc -->
   <p><a name="doc_002dsort"></a>

<div class="defun">
&mdash; Loadable Function: [<var>s</var>, <var>i</var>] = <b>sort</b> (<var>x</var>)<var><a name="index-sort-1652"></a></var><br>
&mdash; Loadable Function: [<var>s</var>, <var>i</var>] = <b>sort</b> (<var>x, dim</var>)<var><a name="index-sort-1653"></a></var><br>
&mdash; Loadable Function: [<var>s</var>, <var>i</var>] = <b>sort</b> (<var>x, mode</var>)<var><a name="index-sort-1654"></a></var><br>
&mdash; Loadable Function: [<var>s</var>, <var>i</var>] = <b>sort</b> (<var>x, dim, mode</var>)<var><a name="index-sort-1655"></a></var><br>
<blockquote><p>Return a copy of <var>x</var> with the elements arranged in increasing
order.  For matrices, <code>sort</code> orders the elements within columns

        <p>For example:

     <pre class="example">          sort ([1, 2; 2, 3; 3, 1])
               &rArr;  1  1
                   2  2
                   3  3
</pre>
        <p>If the optional argument <var>dim</var> is given, then the matrix is sorted
along the dimension defined by <var>dim</var>.  The optional argument <code>mode</code>
defines the order in which the values will be sorted.  Valid values of
<code>mode</code> are `ascend' or `descend'.

        <p>The <code>sort</code> function may also be used to produce a matrix
containing the original row indices of the elements in the sorted
matrix.  For example:

     <pre class="example">          [s, i] = sort ([1, 2; 2, 3; 3, 1])
               &rArr; s = 1  1
                      2  2
                      3  3
               &rArr; i = 1  3
                      2  1
                      3  2
</pre>
        <p>For equal elements, the indices are such that equal elements are listed
in the order in which they appeared in the original list.

        <p>Sorting of complex entries is done first by magnitude (<code>abs (</code><var>z</var><code>)</code>)
and for any ties by phase angle (<code>angle (z)</code>).  For example:

     <pre class="example">          sort ([1+i; 1; 1-i])
               &rArr; 1 + 0i
                  1 - 1i
                  1 + 1i
</pre>
        <p>NaN values are treated as being greater than any other value and are sorted
to the end of the list.

        <p>The <code>sort</code> function may also be used to sort strings and cell arrays
of strings, in which case ASCII dictionary order (uppercase 'A' precedes
lowercase 'a') of the strings is used.

        <p>The algorithm used in <code>sort</code> is optimized for the sorting of partially
ordered lists. 
</p></blockquote></div>

<!-- sortrows scripts/general/sortrows.m -->
   <p><a name="doc_002dsortrows"></a>

<div class="defun">
&mdash; Function File: [<var>s</var>, <var>i</var>] = <b>sortrows</b> (<var>A</var>)<var><a name="index-sortrows-1656"></a></var><br>
&mdash; Function File: [<var>s</var>, <var>i</var>] = <b>sortrows</b> (<var>A, c</var>)<var><a name="index-sortrows-1657"></a></var><br>
<blockquote><p>Sort the rows of the matrix <var>A</var> according to the order of the
columns specified in <var>c</var>.  If <var>c</var> is omitted, a
lexicographical sort is used.  By default ascending order is used
however if elements of <var>c</var> are negative then the corresponding
column is sorted in descending order. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dsort.html#doc_002dsort">sort</a>. 
</p></blockquote></div>

<!-- issorted src/data.cc -->
   <p><a name="doc_002dissorted"></a>

<div class="defun">
&mdash; Built-in Function:  <b>issorted</b> (<var>a</var>)<var><a name="index-issorted-1658"></a></var><br>
&mdash; Built-in Function:  <b>issorted</b> (<var>a, mode</var>)<var><a name="index-issorted-1659"></a></var><br>
&mdash; Built-in Function:  <b>issorted</b> (<var>a, "rows", mode</var>)<var><a name="index-issorted-1660"></a></var><br>
<blockquote><p>Return true if the array is sorted according to <var>mode</var>, which
may be either "ascending", "descending", or "either".  By default,
 <var>mode</var> is "ascending".  NaNs are treated in the same manner as
<code>sort</code>.

        <p>If the optional argument "rows" is supplied, check whether
the array is sorted by rows as output by the function <code>sortrows</code>
(with no options).

        <p>This function does not support sparse matrices. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dsort.html#doc_002dsort">sort</a>, <a href="doc_002dsortrows.html#doc_002dsortrows">sortrows</a>. 
</p></blockquote></div>

<!-- nth_element src/data.cc -->
   <p><a name="doc_002dnth_005felement"></a>

<div class="defun">
&mdash; Built-in Function:  <b>nth_element</b> (<var>x, n</var>)<var><a name="index-nth_005felement-1661"></a></var><br>
&mdash; Built-in Function:  <b>nth_element</b> (<var>x, n, dim</var>)<var><a name="index-nth_005felement-1662"></a></var><br>
<blockquote><p>Select the n-th smallest element of a vector, using the ordering defined by
<code>sort</code>.  In other words, the result is equivalent to
<code>sort(</code><var>x</var><code>)(</code><var>n</var><code>)</code>. 
<var>n</var> can also be a contiguous range, either ascending <code>l:u</code>
or descending <code>u:-1:l</code>, in which case a range of elements is returned. 
If <var>x</var> is an array, <code>nth_element</code> operates along the dimension
defined by <var>dim</var>, or the first non-singleton dimension if <var>dim</var> is
not given.

        <p>nth_element encapsulates the C++ standard library algorithms nth_element and
partial_sort.  On average, the complexity of the operation is O(M*log(K)),
where <code>M&nbsp;=&nbsp;size&nbsp;(</code><var>x</var><code>,&nbsp;</code><var>dim</var><code>)</code><!-- /@w --> and
<code>K&nbsp;=&nbsp;length&nbsp;(</code><var>n</var><code>)</code><!-- /@w -->. 
This function is intended for cases where the ratio K/M is small; otherwise,
it may be better to use <code>sort</code>. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dsort.html#doc_002dsort">sort</a>, <a href="doc_002dmin.html#doc_002dmin">min</a>, <a href="doc_002dmax.html#doc_002dmax">max</a>. 
</p></blockquote></div>

   <p><a name="doc_002dtriu"></a><!-- tril src/DLD-FUNCTIONS/tril.cc -->
<a name="doc_002dtril"></a>

<div class="defun">
&mdash; Function File:  <b>tril</b> (<var>A</var>)<var><a name="index-tril-1663"></a></var><br>
&mdash; Function File:  <b>tril</b> (<var>A, k</var>)<var><a name="index-tril-1664"></a></var><br>
&mdash; Function File:  <b>tril</b> (<var>A, k, pack</var>)<var><a name="index-tril-1665"></a></var><br>
&mdash; Function File:  <b>triu</b> (<var>A</var>)<var><a name="index-triu-1666"></a></var><br>
&mdash; Function File:  <b>triu</b> (<var>A, k</var>)<var><a name="index-triu-1667"></a></var><br>
&mdash; Function File:  <b>triu</b> (<var>A, k, pack</var>)<var><a name="index-triu-1668"></a></var><br>
<blockquote><p>Return a new matrix formed by extracting the lower (<code>tril</code>)
or upper (<code>triu</code>) triangular part of the matrix <var>A</var>, and
setting all other elements to zero.  The second argument is optional,
and specifies how many diagonals above or below the main diagonal should
also be set to zero.

        <p>The default value of <var>k</var> is zero, so that <code>triu</code> and
<code>tril</code> normally include the main diagonal as part of the result.

        <p>If the value of <var>k</var> is nonzero integer, the selection of elementsstarts at an offset of <var>k</var> diagonals above or below the maindiagonal; above for positive <var>k</var> and below for negative <var>k</var>. 
The absolute value of <var>k</var> must not be greater than the number of
sub-diagonals or super-diagonals.

        <p>For example:

     <pre class="example">          tril (ones (3), -1)
               &rArr;  0  0  0
                   1  0  0
                   1  1  0
</pre>
        <p class="noindent">and

     <pre class="example">          tril (ones (3), 1)
               &rArr;  1  1  0
                   1  1  1
                   1  1  1
</pre>
        <p>If the option "pack" is given as third argument, the extracted elements
are not inserted into a matrix, but rather stacked column-wise one above
other. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002ddiag.html#doc_002ddiag">diag</a>. 
</p></blockquote></div>

<!-- vec src/data.cc -->
   <p><a name="doc_002dvec"></a>

<div class="defun">
&mdash; Built-in Function: <var>v</var> = <b>vec</b> (<var>x</var>)<var><a name="index-vec-1669"></a></var><br>
&mdash; Built-in Function: <var>v</var> = <b>vec</b> (<var>x, dim</var>)<var><a name="index-vec-1670"></a></var><br>
<blockquote><p>Return the vector obtained by stacking the columns of the matrix <var>x</var>
one above the other.  Without <var>dim</var> this is equivalent to
<var>x</var><code>(:)</code>.  If <var>dim</var> is supplied, the dimensions of <var>v</var>
are set to <var>dim</var> with all elements along the last dimension. 
This is equivalent to <code>shiftdim (</code><var>x</var><code>(:), 1-</code><var>dim</var><code>)</code>. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dvech.html#doc_002dvech">vech</a>. 
</p></blockquote></div>

<!-- vech scripts/linear-algebra/vech.m -->
   <p><a name="doc_002dvech"></a>

<div class="defun">
&mdash; Function File:  <b>vech</b> (<var>x</var>)<var><a name="index-vech-1671"></a></var><br>
<blockquote><p>Return the vector obtained by eliminating all supradiagonal elements of
the square matrix <var>x</var> and stacking the result one column above the
other.  This has uses in matrix calculus where the underlying matrix
is symmetric and it would be pointless to keep values above the main
diagonal. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dvec.html#doc_002dvec">vec</a>. 
</p></blockquote></div>

<!-- prepad scripts/general/prepad.m -->
   <p><a name="doc_002dprepad"></a>

<div class="defun">
&mdash; Function File:  <b>prepad</b> (<var>x, l</var>)<var><a name="index-prepad-1672"></a></var><br>
&mdash; Function File:  <b>prepad</b> (<var>x, l, c</var>)<var><a name="index-prepad-1673"></a></var><br>
&mdash; Function File:  <b>prepad</b> (<var>x, l, c, dim</var>)<var><a name="index-prepad-1674"></a></var><br>
<blockquote><p>Prepend the scalar value <var>c</var> to the vector <var>x</var> until it is of length
<var>l</var>.  If <var>c</var> is not given, a value of 0 is used.

        <p>If <code>length (</code><var>x</var><code>) &gt; </code><var>l</var>, elements from the beginning of
<var>x</var> are removed until a vector of length <var>l</var> is obtained.

        <p>If <var>x</var> is a matrix, elements are prepended or removed from each row.

        <p>If the optional argument <var>dim</var> is given, operate along this
dimension. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dpostpad.html#doc_002dpostpad">postpad</a>, <a href="doc_002dcat.html#doc_002dcat">cat</a>, <a href="doc_002dresize.html#doc_002dresize">resize</a>. 
</p></blockquote></div>

<!-- postpad scripts/general/postpad.m -->
   <p><a name="doc_002dpostpad"></a>

<div class="defun">
&mdash; Function File:  <b>postpad</b> (<var>x, l</var>)<var><a name="index-postpad-1675"></a></var><br>
&mdash; Function File:  <b>postpad</b> (<var>x, l, c</var>)<var><a name="index-postpad-1676"></a></var><br>
&mdash; Function File:  <b>postpad</b> (<var>x, l, c, dim</var>)<var><a name="index-postpad-1677"></a></var><br>
<blockquote><p>Append the scalar value <var>c</var> to the vector <var>x</var> until it is of length
<var>l</var>.  If <var>c</var> is not given, a value of 0 is used.

        <p>If <code>length (</code><var>x</var><code>) &gt; </code><var>l</var>, elements from the end of
<var>x</var> are removed until a vector of length <var>l</var> is obtained.

        <p>If <var>x</var> is a matrix, elements are appended or removed from each row.

        <p>If the optional argument <var>dim</var> is given, operate along this
dimension. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dprepad.html#doc_002dprepad">prepad</a>, <a href="doc_002dcat.html#doc_002dcat">cat</a>, <a href="doc_002dresize.html#doc_002dresize">resize</a>. 
</p></blockquote></div>

<!-- diag src/data.cc -->
   <p><a name="doc_002ddiag"></a>

<div class="defun">
&mdash; Built-in Function: <var>M</var> = <b>diag</b> (<var>v</var>)<var><a name="index-diag-1678"></a></var><br>
&mdash; Built-in Function: <var>M</var> = <b>diag</b> (<var>v, k</var>)<var><a name="index-diag-1679"></a></var><br>
&mdash; Built-in Function: <var>M</var> = <b>diag</b> (<var>v, m, n</var>)<var><a name="index-diag-1680"></a></var><br>
&mdash; Built-in Function: <var>v</var> = <b>diag</b> (<var>M</var>)<var><a name="index-diag-1681"></a></var><br>
&mdash; Built-in Function: <var>v</var> = <b>diag</b> (<var>M, k</var>)<var><a name="index-diag-1682"></a></var><br>
<blockquote><p>Return a diagonal matrix with vector <var>v</var> on diagonal <var>k</var>.  The
second argument is optional.  If it is positive, the vector is placed on
the <var>k</var>-th super-diagonal.  If it is negative, it is placed on the
<var>-k</var>-th sub-diagonal.  The default value of <var>k</var> is 0, and the
vector is placed on the main diagonal.  For example:

     <pre class="example">          diag ([1, 2, 3], 1)
               &rArr;  0  1  0  0
                   0  0  2  0
                   0  0  0  3
                   0  0  0  0
</pre>
        <p class="noindent">The 3-input form returns a diagonal matrix with vector <var>v</var> on the main
diagonal and the resulting matrix being of size <var>m</var> rows x <var>n</var>
columns.

        <p>Given a matrix argument, instead of a vector, <code>diag</code> extracts the
<var>k</var>-th diagonal of the matrix. 
</p></blockquote></div>

<!-- blkdiag scripts/general/blkdiag.m -->
   <p><a name="doc_002dblkdiag"></a>

<div class="defun">
&mdash; Function File:  <b>blkdiag</b> (<var>A, B, C, <small class="dots">...</small></var>)<var><a name="index-blkdiag-1683"></a></var><br>
<blockquote><p>Build a block diagonal matrix from <var>A</var>, <var>B</var>, <var>C</var>, <small class="dots">...</small>
All the arguments must be numeric and are two-dimensional matrices or
scalars.  If any argument is of type sparse, the output will also be
sparse. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002ddiag.html#doc_002ddiag">diag</a>, <a href="doc_002dhorzcat.html#doc_002dhorzcat">horzcat</a>, <a href="doc_002dvertcat.html#doc_002dvertcat">vertcat</a>, <a href="doc_002dsparse.html#doc_002dsparse">sparse</a>. 
</p></blockquote></div>

   </body></html>