<!--
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2008 - INRIA - Farid BELAHCENE
- * Copyright (C) 2013 - Samuel GOUGEON: restriction to decimal numbers removed. Examples added for booleans, integer-encoded numbers, text, polynomials, rationals
+ * Copyright (C) 2013, 2016 - Samuel GOUGEON : 5.5.0 extensions, page overhauled
*
* Copyright (C) 2012 - 2016 - Scilab Enterprises
*
* along with this program.
*
-->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="flipdim" xml:lang="en">
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
+ xmlns:scilab="http://www.scilab.org" xml:id="flipdim" xml:lang="en">
<refnamediv>
<refname>flipdim</refname>
- <refpurpose>reverses the order of (blocs of) rows, columns, pages.. of a matrix or hypermatrix</refpurpose>
+ <refpurpose>reverses the order of (blocks of) rows, columns, pages.. of a matrix or hypermatrix</refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>Syntax</title>
- <synopsis>y = flipdim(x, dim [,sb])</synopsis>
+ <synopsis>
+ y = flipdim(x, dim)
+ y = flipdim(x, dim, blockSize)
+ </synopsis>
</refsynopsisdiv>
<refsection role="parameters">
<title>Arguments</title>
<varlistentry>
<term>x, y</term>
<listitem>
- <para>scalars, vectors, matrices, or hypermatrices of any type, of same sizes</para>
+ <para>
+ vectors, matrices, or hypermatrices of any regular data type.
+ <varname>y</varname> gets the sizes of <varname>x</varname>.
+ </para>
</listitem>
</varlistentry>
<varlistentry>
<term>dim</term>
<listitem>
- <para>a positive integer, the dimension number along which the flipping should occur</para>
+ <para>
+ positive integer : index of the dimension / direction of <literal>x</literal>
+ along which the order of <varname>x</varname> components must be inverted.
+ </para>
</listitem>
</varlistentry>
<varlistentry>
- <term>sb</term>
+ <term>blockSize</term>
<listitem>
- <para>a positive integer, the size of the blocks to permute</para>
+ <para>
+ a positive integer, sub-multiple of <literal>size(x,dim)</literal>:
+ number of rows, of columns, of pages etc in each block. Default value = 1
+ </para>
</listitem>
</varlistentry>
</variablelist>
<refsection role="description">
<title>Description</title>
<para>
- Given <literal>x</literal>, a scalar/vector/matrix/hypermatrix of any type and
- two positive integers <literal>dim</literal> and <literal>sb</literal>,
- this function flips the x components by blocks of size <literal>sb</literal>
- along the dimension number <literal>dim</literal> of <literal>x</literal>
- (<literal>x</literal> and <literal>y</literal> have the same size).
+ <literal>flipdim(x, 1)</literal> inverts the order of
+ <emphasis role="italic">rows</emphasis> in the matrix or hypermatrix
+ <varname>x</varname>.
</para>
<para>
- The optional parameter <literal>sb</literal> (for Size Block) allows flipping
- <literal>x</literal> by blocks of size <literal>sb*size(x,2)</literal>
- (<literal>dim=1</literal>) or <literal>size(x,1)*sb</literal> (<literal>dim=2</literal>).
+ <literal>flipdim(x, 2)</literal> inverts the order of
+ <emphasis role="italic">columns</emphasis> of <varname>x</varname>.
+ </para>
+ <para>
+ <literal>flipdim(x, 3)</literal> inverts the order of
+ <emphasis role="italic">pages</emphasis> in the hypermatrix
+ <varname>x</varname>. Etc.
+ </para>
+ <para>
+ The optional parameter <literal>blockSize</literal> allows splitting
+ <varname>x</varname> in <literal>size(x,1)/blockSize</literal> blocks
+ of <varname>blockSize</varname> rows (<literal>dim=1</literal>),
+ or in <literal>size(x,2)/blockSize</literal> blocks of <varname>blockSize</varname>
+ columns (<literal>dim=2</literal>), etc (<literal>dim>2</literal>)
+ and to invert their order.
+ In each block, the order of components (rows, columns, pages etc)
+ is unchanged.
</para>
</refsection>
<refsection role="examples">
<title>Examples</title>
<programlisting role="example"><![CDATA[
-// Example 1: flip x components along the first dimension
+// Example 1: flip x rows (= components along the first dimension)
x = [1 2 3 4; 5 6 7 8]
-dim = 1
-y = flipdim(x, dim)
+y = flipdim(x, 1)
-// Example 2: flip x components along the second dimension
-dim = 2
-y = flipdim(x, dim)
+// Example 2: flip x columns (= components along the second dimension)
+y = flipdim(x, 2)
-// Example 3: flip x components along the third dimension
+// Example 3: flip x pages (= components along the third dimension)
x = matrix(1:24, [3 2 4])
-dim = 3
-y = flipdim(x, dim)
+y = flipdim(x, 3)
// Example 4: the first example with complex
x = [1+%i 2*%i 3 4; 5 6-%i 7 8*%pi*%i]
-dim = 1
-y = flipdim(x, dim)
+y = flipdim(x, 1)
// Integer-encoded numbers:
x = int16(grand(4, 3, 2, "uin", -9, 9))
flipdim(r, 2)
]]></programlisting>
<para>
- Examples using <literal>sb</literal>:
+ Examples using <literal>blockSize</literal> :
</para>
<programlisting role="example"><![CDATA[
X = [0 1 2 3 4 5 6 7 8 9 10 11];
flipdim(X, 2, 4) // => [8 9 10 11 4 5 6 7 0 1 2 3]
flipdim(X, 2, 6) // => [6 7 8 9 10 11 0 1 2 3 4 5]
-// Error if sb does not divide the targeted dimension of x.
-y = flipdim(x, 2, 5); // size(X) = [1 12] and sb=5 does not divide 12.
+// Error if blockSize does not divide the targeted dimension of x.
+y = flipdim(x, 2, 5); // size(X) = [1 12] and blockSize=5 does not divide 12.
]]></programlisting>
+ <para>Example of results:</para>
+ <screen><![CDATA[
+--> x
+ x =
+ -5 -2 0 9
+ 0 -7 -6 9
+ -1 -8 -7 8
+
+--> flipdim(x, 1)
+ ans =
+ -1 -8 -7 8
+ 0 -7 -6 9
+ -5 -2 0 9
+
+--> flipdim(x, 2)
+ ans =
+ 9 0 -2 -5
+ 9 -6 -7 0
+ 8 -7 -8 -1
+]]></screen>
+ <para></para>
+ <screen><![CDATA[
+--> x
+ x =
+(:,:,1)
+ 9 4 -3
+ -4 -8 -3
+
+(:,:,2)
+ 5 8 9
+ 4 4 9
+
+--> flipdim(x, 3)
+ ans =
+(:,:,1)
+ 5 8 9
+ 4 4 9
+
+(:,:,2)
+ 9 4 -3
+ -4 -8 -3
+]]></screen>
+ <para></para>
+ <screen><![CDATA[
+--> x
+ x =
+ -2 3 -5 9 -4 -8
+ 2 8 4 -9 6 -6
+ -9 8 3 4 -3 4
+
+--> flipdim(x, 2, 2)
+ ans =
+ -4 -8 -5 9 -2 3
+ 6 -6 4 -9 2 8
+ -3 4 3 4 -9 8
+
+--> flipdim(x, 2, 3)
+ ans =
+ 9 -4 -8 -2 3 -5
+ -9 6 -6 2 8 4
+ 4 -3 4 -9 8 3
+]]></screen>
+ </refsection>
+ <refsection role="see also">
+ <title>See also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="fftshift">fftshift</link>
+ </member>
+ <member>
+ <link linkend="ifftshift">ifftshift</link>
+ </member>
+ <member>
+ <link linkend="colon">colon</link>
+ </member>
+ </simplelist>
</refsection>
<refsection role="history">
<title>History</title>
<revision>
<revnumber>5.5.0</revnumber>
<revremark>
- Extension from decimals to any type: booleans, integers, strings, polynomials and rationals.
- New input argument <literal>sb</literal> to flip <literal>x</literal> blockwise.
+ <itemizedlist>
+ <listitem>
+ Extension to all regular data types: booleans, integers,
+ strings, polynomials, rationals, graphic handles, etc.
+ </listitem>
+ <listitem>
+ New input argument <literal>blockSize</literal> to flip
+ <literal>x</literal> blockwise.
+ </listitem>
+ </itemizedlist>
</revremark>
</revision>
</revhistory>