Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.1.0 - Português


flipdim

reverses the order of (blocks of) rows, columns, pages.. of an array

Syntax

y = flipdim(x, dim)
y = flipdim(x, dim, blockSize)

Arguments

x, y

vectors, matrices, or hypermatrices of any regular data type, or cells array. y gets the sizes of x.

dim

positive integer : index of the dimension / direction of x along which the order of x components must be inverted.

blockSize

a positive integer, sub-multiple of size(x,dim): number of rows, of columns, of pages etc in each block. Default value = 1

Description

flipdim(x, 1) inverts the order of rows of x.

flipdim(x, 2) inverts the order of columns of x.

flipdim(x, 3) inverts the order of pages of x. Etc.

The optional parameter blockSize allows splitting x in size(x,1)/blockSize blocks of blockSize rows (dim=1), or in size(x,2)/blockSize blocks of blockSize columns (dim=2), etc (dim>2) and to invert their order. In each block, the order of components (rows, columns, pages etc) is unchanged.

Examples

// Example 1: flip x rows (= components along the first dimension)
x = [1 2 3 4; 5 6 7 8]
y = flipdim(x, 1)

// Example 2: flip x columns (= components along the second dimension)
y = flipdim(x, 2)

// Example 3: flip x pages (= components along the third dimension)
x = matrix(1:24, [3 2 4])
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]
y = flipdim(x, 1)

// Integer-encoded numbers:
x = int16(grand(4, 3, 2, "uin", -9, 9))
y = flipdim(x, 1)

// Booleans:
x = (grand(3, 4, "uin", -9, 9) > 0)
y = flipdim(x, 2)

// Texts:
x = matrix(strsplit("a":"x", 1:23), 4, 6);
x = x+x
flipdim(x, 2)

// Polynomials:
x = inv_coeff(grand(3, 9, "uin", 0, 3), 2)
flipdim(x, 1)

// Rationals:
n = inv_coeff(grand(3, 9, "uin", 0, 3), 2);
d = inv_coeff(grand(3, 9, "uin", 0, 3), 2);
d(d == 0) = 1;
r = n./d
flipdim(r, 2)

Examples using blockSize :

X = [0 1 2 3 4 5 6 7 8 9 10 11];
flipdim(X, 2, 2) // => [10 11   8 9   6 7   4 5   2 3   0 1] // Block size = 2.
flipdim(X, 2, 3) // => [9 10 11   6 7 8   3 4 5   0 1 2]
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 blockSize does not divide the targeted dimension of x.
try
    y = flipdim(X, 2, 5); // size(X) = [1 12] and blockSize=5 does not divide 12.
catch
    disp("size(X) = [1 12] and blockSize=5 does not divide 12");
end

Example of results:

--> 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

--> 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

--> 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

See also

  • circshift — circularly shifts elements or subarrays of an array (regular, of structures, cells, custom)
  • fftshift — rearranges the fft output, moving the zero frequency to the center of the spectrum
  • ifftshift — inverse of fftshift
  • colon — operador dois pontos

History

VersãoDescrição
5.5.0
  • Extension to all regular data types: booleans, integers, strings, polynomials, rationals, graphic handles, etc.
  • New input argument blockSize to flip x blockwise.
Report an issue
<< circshift Matrix manipulation matrix >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jun 17 17:53:23 CEST 2024